Skip to content
Permalink
Browse files

Calling Promise's function as constructor should throw an error

Added appropriate attributes for that.
  • Loading branch information...
akroshg committed Mar 9, 2019
1 parent a247f4f commit f74c5a94839c1bbb28838e984f637dbd990dbadc
Showing with 17 additions and 4 deletions.
  1. +4 −4 lib/Runtime/Library/JavascriptLibrary.cpp
  2. +13 −0 test/Bugs/misc_bugs.js
@@ -6136,7 +6136,7 @@ namespace Js
{
Assert(scriptContext->GetConfig()->IsES6PromiseEnabled());

FunctionInfo* functionInfo = RecyclerNew(this->GetRecycler(), FunctionInfo, entryPoint);
FunctionInfo* functionInfo = RecyclerNew(this->GetRecycler(), FunctionInfo, entryPoint, FunctionInfo::Attributes::ErrorOnNew);
DynamicType* type = CreateDeferredPrototypeFunctionType(entryPoint);

return RecyclerNewEnumClass(this->GetRecycler(), EnumFunctionClass, JavascriptPromiseReactionTaskFunction, type, functionInfo, reaction, argument);
@@ -6146,7 +6146,7 @@ namespace Js
{
Assert(scriptContext->GetConfig()->IsES6PromiseEnabled());

FunctionInfo* functionInfo = RecyclerNew(this->GetRecycler(), FunctionInfo, entryPoint);
FunctionInfo* functionInfo = RecyclerNew(this->GetRecycler(), FunctionInfo, entryPoint, FunctionInfo::Attributes::ErrorOnNew);
DynamicType* type = CreateDeferredPrototypeFunctionType(entryPoint);

return RecyclerNewEnumClass(this->GetRecycler(), EnumFunctionClass, JavascriptPromiseResolveThenableTaskFunction, type, functionInfo, promise, thenable, thenFunction);
@@ -6169,7 +6169,7 @@ namespace Js
{
Assert(scriptContext->GetConfig()->IsES6PromiseEnabled());

FunctionInfo* functionInfo = RecyclerNew(this->GetRecycler(), FunctionInfo, entryPoint);
FunctionInfo* functionInfo = RecyclerNew(this->GetRecycler(), FunctionInfo, entryPoint, FunctionInfo::Attributes::ErrorOnNew);
DynamicType* type = DynamicType::New(scriptContext, TypeIds_Function, functionPrototype, entryPoint, GetDeferredAnonymousFunctionTypeHandler());

JavascriptPromiseThenFinallyFunction* function = RecyclerNewEnumClass(this->GetRecycler(), EnumFunctionClass, JavascriptPromiseThenFinallyFunction, type, functionInfo, OnFinally, Constructor, shouldThrow);
@@ -6182,7 +6182,7 @@ namespace Js
{
Assert(scriptContext->GetConfig()->IsES6PromiseEnabled());

FunctionInfo* functionInfo = RecyclerNew(this->GetRecycler(), FunctionInfo, entryPoint);
FunctionInfo* functionInfo = RecyclerNew(this->GetRecycler(), FunctionInfo, entryPoint, FunctionInfo::Attributes::ErrorOnNew);
DynamicType* type = CreateDeferredPrototypeFunctionType(entryPoint);

return RecyclerNewEnumClass(this->GetRecycler(), EnumFunctionClass, JavascriptPromiseThunkFinallyFunction, type, functionInfo, value, shouldThrow);
@@ -210,6 +210,19 @@ var tests = [
catch (e) {
}
}
},
{
name: "calling promise's function as constructor should not be allowed",
body: function () {
var var_0 = new Promise(function () {});
var var_1 = function () {};

var_0.then = function (a, b) {
var_2 = b;
};
var_3 = Promise.prototype.finally.call(var_0, var_1);
assert.throws(() => { new var_2([]).var_3(); },TypeError);
}
}

];

0 comments on commit f74c5a9

Please sign in to comment.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.