Skip to content

Commit

Permalink
Fix incorrect tests for CreateDynamicFunction
Browse files Browse the repository at this point in the history
  • Loading branch information
jedel1043 committed Feb 22, 2024
1 parent 0fd1675 commit be393b1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 29 deletions.
24 changes: 11 additions & 13 deletions test/built-ins/Function/S15.3.2.1_A3_T1.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,28 @@

/*---
info: |
When the Function constructor is called with arguments p, body the following steps are taken:
i) Let Result(i) be the first argument
ii) Let P be ToString(Result(i))
iii) Call ToString(body)
iv) If P is not parsable as a FormalParameterList_opt then throw a SyntaxError exception
v) If body is not parsable as FunctionBody then throw a SyntaxError exception
vi) Create a new Function object as specified in 13.2 with parameters specified by parsing P as a FormalParameterListopt and body specified by parsing body as a FunctionBody
Pass in a scope chain consisting of the global object as the Scope parameter
vii) Return Result(vi)
The abstract operation CreateDynamicFunction ... performs the following steps when called:
...
7. Let bodyString be ? ToString(bodyArg).
8. Let parameterStrings be a new empty List.
9. For each element arg of parameterArgs, do
a. Append ? ToString(arg) to parameterStrings.
...
es5id: 15.3.2.1_A3_T1
description: >
Values of the function constructor arguments are
"{toString:function(){throw 1;}}" and "{toString:function(){throw
'body';}}"
"{toString:function(){throw "a";}}" and
"{toString:function(){throw 1;}}"
---*/

var p = {
toString: function() {
throw 1;
throw "a";
}
};
var body = {
toString: function() {
throw "body";
throw 1;
}
};

Expand Down
30 changes: 14 additions & 16 deletions test/built-ins/Function/S15.3.2.1_A3_T3.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,37 @@

/*---
info: |
When the Function constructor is called with arguments p, body the following steps are taken:
i) Let Result(i) be the first argument
ii) Let P be ToString(Result(i))
iii) Call ToString(body)
iv) If P is not parsable as a FormalParameterList_opt then throw a SyntaxError exception
v) If body is not parsable as FunctionBody then throw a SyntaxError exception
vi) Create a new Function object as specified in 13.2 with parameters specified by parsing P as a FormalParameterListopt and body specified by parsing body as a FunctionBody
Pass in a scope chain consisting of the global object as the Scope parameter
vii) Return Result(vi)
The abstract operation CreateDynamicFunction ... performs the following steps when called:
...
7. Let bodyString be ? ToString(bodyArg).
8. Let parameterStrings be a new empty List.
9. For each element arg of parameterArgs, do
a. Append ? ToString(arg) to parameterStrings.
...
es5id: 15.3.2.1_A3_T3
description: >
Values of the function constructor arguments are
"{toString:function(){p=1;return "a";}}" and
"{toString:function(){throw "body";}}"
"{toString:function(){throw "a";}}" and
"{toString:function(){body=1;return "body";}}"
---*/

var p = {
toString: function() {
p = 1;
return "a";
throw "a";
}
};
var body = {
toString: function() {
throw "body";
body = 1;
return "body";
}
};

try {
var f = new Function(p, body);
throw new Test262Error('#1: test failed');
} catch (e) {
assert.sameValue(e, "body", 'The value of e is expected to be "body"');
assert.sameValue(e, "a", 'The value of e is expected to be "a"');
}

assert.sameValue(p, 1, 'The value of p is expected to be 1');
assert.sameValue(body, 1, 'The value of body is expected to be 1');

0 comments on commit be393b1

Please sign in to comment.