Skip to content
Permalink
Browse files

[MERGE #6005 @akroshg] Calling Promise's function as constructor shou…

…ld throw an error

Merge pull request #6005 from akroshg:promise

Added appropriate attributes for that.
  • Loading branch information...
akroshg committed Mar 12, 2019
2 parents 28b007f + f74c5a9 commit 178f6522962ad935f01da156b7f73b2fee5d5eb4
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 178f652

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.