Title: [201892] trunk
Revision
201892
Author
[email protected]
Date
2016-06-09 16:30:39 -0700 (Thu, 09 Jun 2016)

Log Message

ES6: Reusing function name as a parameter name shouldn't throw Syntax Error
https://bugs.webkit.org/show_bug.cgi?id=158575

Reviewed by Benjamin Poulain.

Source/_javascript_Core:

The check for a parameter with a duplicate name doesn't take into account the
type of the prior variable.  Added a check that the duplicate is also a
parameter.

See the relevant spec section at:
http://www.ecma-international.org/ecma-262/6.0/#sec-function-definitions-static-semantics-early-errors

* parser/Parser.h:
(JSC::Scope::declareParameter):

LayoutTests:

Added a new test case.

* js/basic-strict-mode-expected.txt:
* js/script-tests/basic-strict-mode.js:

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (201891 => 201892)


--- trunk/LayoutTests/ChangeLog	2016-06-09 22:55:52 UTC (rev 201891)
+++ trunk/LayoutTests/ChangeLog	2016-06-09 23:30:39 UTC (rev 201892)
@@ -1,3 +1,15 @@
+2016-06-09  Michael Saboff  <[email protected]>
+
+        ES6: Reusing function name as a parameter name shouldn't throw Syntax Error
+        https://bugs.webkit.org/show_bug.cgi?id=158575
+
+        Reviewed by Benjamin Poulain.
+
+        Added a new test case.
+
+        * js/basic-strict-mode-expected.txt:
+        * js/script-tests/basic-strict-mode.js:
+
 2016-06-09  Antoine Quint  <[email protected]>
 
         Changing canvas height immediately after page load does not relayout canvas

Modified: trunk/LayoutTests/js/basic-strict-mode-expected.txt (201891 => 201892)


--- trunk/LayoutTests/js/basic-strict-mode-expected.txt	2016-06-09 22:55:52 UTC (rev 201891)
+++ trunk/LayoutTests/js/basic-strict-mode-expected.txt	2016-06-09 23:30:39 UTC (rev 201892)
@@ -68,6 +68,9 @@
 PASS (function f(arg){'use strict'; f.caller; })() threw exception TypeError: 'arguments', 'callee', and 'caller' cannot be accessed in strict mode..
 PASS (function f(arg){'use strict'; f.arguments=5; })() threw exception TypeError: 'arguments', 'callee', and 'caller' cannot be accessed in strict mode..
 PASS (function f(arg){'use strict'; f.caller=5; })() threw exception TypeError: 'arguments', 'callee', and 'caller' cannot be accessed in strict mode..
+PASS (function a(a){'use strict'; return a+2; })(40) is 42
+PASS var foo = function a(a){'use strict'; return a+2; }; foo(40) is 42
+PASS var o = {foo: function a(a){'use strict'; return a+2; } }; o.foo(40) is 42
 PASS "caller" in function(){"use strict"} is true
 PASS (function(){"use strict";}).hasOwnProperty("caller") is true
 PASS "arguments" in function(){"use strict"} is true

Modified: trunk/LayoutTests/js/script-tests/basic-strict-mode.js (201891 => 201892)


--- trunk/LayoutTests/js/script-tests/basic-strict-mode.js	2016-06-09 22:55:52 UTC (rev 201891)
+++ trunk/LayoutTests/js/script-tests/basic-strict-mode.js	2016-06-09 23:30:39 UTC (rev 201892)
@@ -85,6 +85,9 @@
 shouldThrow("(function f(arg){'use strict'; f.caller; })()");
 shouldThrow("(function f(arg){'use strict'; f.arguments=5; })()");
 shouldThrow("(function f(arg){'use strict'; f.caller=5; })()");
+shouldBe("(function a(a){'use strict'; return a+2; })(40)", "42");
+shouldBe("var foo = function a(a){'use strict'; return a+2; }; foo(40)", "42");
+shouldBe("var o = {foo: function a(a){'use strict'; return a+2; } }; o.foo(40)", "42");
 
 // arguments/caller poisoning should be visible but not throw with 'in' & 'hasOwnProperty'.
 shouldBeTrue('"caller" in function(){"use strict"}');

Modified: trunk/Source/_javascript_Core/ChangeLog (201891 => 201892)


--- trunk/Source/_javascript_Core/ChangeLog	2016-06-09 22:55:52 UTC (rev 201891)
+++ trunk/Source/_javascript_Core/ChangeLog	2016-06-09 23:30:39 UTC (rev 201892)
@@ -1,3 +1,20 @@
+2016-06-09  Michael Saboff  <[email protected]>
+
+        ES6: Reusing function name as a parameter name shouldn't throw Syntax Error
+        https://bugs.webkit.org/show_bug.cgi?id=158575
+
+        Reviewed by Benjamin Poulain.
+
+        The check for a parameter with a duplicate name doesn't take into account the
+        type of the prior variable.  Added a check that the duplicate is also a
+        parameter.
+
+        See the relevant spec section at:
+        http://www.ecma-international.org/ecma-262/6.0/#sec-function-definitions-static-semantics-early-errors
+
+        * parser/Parser.h:
+        (JSC::Scope::declareParameter):
+
 2016-06-09  Chris Dumez  <[email protected]>
 
         Unreviewed, rolling out r201836, r201845, and r201848.

Modified: trunk/Source/_javascript_Core/parser/Parser.h (201891 => 201892)


--- trunk/Source/_javascript_Core/parser/Parser.h	2016-06-09 22:55:52 UTC (rev 201891)
+++ trunk/Source/_javascript_Core/parser/Parser.h	2016-06-09 23:30:39 UTC (rev 201892)
@@ -479,9 +479,10 @@
         DeclarationResultMask result = DeclarationResult::Valid;
         bool isArgumentsIdent = isArguments(m_vm, ident);
         auto addResult = m_declaredVariables.add(ident->impl());
+        bool isValidStrictMode = (addResult.isNewEntry || !addResult.iterator->value.isParameter())
+            && m_vm->propertyNames->eval != *ident && !isArgumentsIdent;
         addResult.iterator->value.clearIsVar();
         addResult.iterator->value.setIsParameter();
-        bool isValidStrictMode = addResult.isNewEntry && m_vm->propertyNames->eval != *ident && !isArgumentsIdent;
         m_isValidStrictMode = m_isValidStrictMode && isValidStrictMode;
         m_declaredParameters.add(ident->impl());
         if (!isValidStrictMode)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to