Title: [202734] trunk/Source/_javascript_Core
Revision
202734
Author
[email protected]
Date
2016-07-01 08:25:35 -0700 (Fri, 01 Jul 2016)

Log Message

ES6: Implement HasRestrictedGlobalProperty when checking for global lexical tier conflicts
https://bugs.webkit.org/show_bug.cgi?id=148763

Patch by Caio Lima <[email protected]> on 2016-07-01
Reviewed by Saam Barati

I've implemented the ES6 spec 8.1.1.4.14
(http://www.ecma-international.org/ecma-262/6.0/index.html#sec-hasrestrictedglobalproperty)
that defines when a global property can be shadowed.

Added some test cases into global-lexical-redeclare-variable.js

* runtime/Executable.cpp:
(JSC::ProgramExecutable::initializeGlobalProperties):
* tests/stress/global-lexical-redeclare-variable.js:
(catch):
* tests/stress/multiple-files-tests/global-lexical-redeclare-variable/eighth.js: Added.
* tests/stress/multiple-files-tests/global-lexical-redeclare-variable/nineth.js: Added.
* tests/stress/multiple-files-tests/global-lexical-redeclare-variable/seventh.js: Added.
* tests/stress/multiple-files-tests/global-lexical-redeclare-variable/sixth.js:
* tests/stress/multiple-files-tests/global-lexical-redeclare-variable/tenth.js: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/Source/_javascript_Core/ChangeLog (202733 => 202734)


--- trunk/Source/_javascript_Core/ChangeLog	2016-07-01 12:46:58 UTC (rev 202733)
+++ trunk/Source/_javascript_Core/ChangeLog	2016-07-01 15:25:35 UTC (rev 202734)
@@ -1,3 +1,26 @@
+2016-07-01  Caio Lima  <[email protected]>
+
+        ES6: Implement HasRestrictedGlobalProperty when checking for global lexical tier conflicts
+        https://bugs.webkit.org/show_bug.cgi?id=148763
+
+        Reviewed by Saam Barati
+
+        I've implemented the ES6 spec 8.1.1.4.14
+        (http://www.ecma-international.org/ecma-262/6.0/index.html#sec-hasrestrictedglobalproperty)
+        that defines when a global property can be shadowed.
+
+        Added some test cases into global-lexical-redeclare-variable.js
+
+        * runtime/Executable.cpp:
+        (JSC::ProgramExecutable::initializeGlobalProperties):
+        * tests/stress/global-lexical-redeclare-variable.js:
+        (catch):
+        * tests/stress/multiple-files-tests/global-lexical-redeclare-variable/eighth.js: Added.
+        * tests/stress/multiple-files-tests/global-lexical-redeclare-variable/nineth.js: Added.
+        * tests/stress/multiple-files-tests/global-lexical-redeclare-variable/seventh.js: Added.
+        * tests/stress/multiple-files-tests/global-lexical-redeclare-variable/sixth.js:
+        * tests/stress/multiple-files-tests/global-lexical-redeclare-variable/tenth.js: Added.
+
 2016-07-01  Youenn Fablet  <[email protected]>
 
         Add a runtime flag for DOM iterators

Modified: trunk/Source/_javascript_Core/runtime/Executable.cpp (202733 => 202734)


--- trunk/Source/_javascript_Core/runtime/Executable.cpp	2016-07-01 12:46:58 UTC (rev 202733)
+++ trunk/Source/_javascript_Core/runtime/Executable.cpp	2016-07-01 15:25:35 UTC (rev 202734)
@@ -605,9 +605,16 @@
         // Check if any new "let"/"const"/"class" will shadow any pre-existing global property names, or "var"/"let"/"const" variables.
         // It's an error to introduce a shadow.
         for (auto& entry : lexicalDeclarations) {
-            if (globalObject->hasProperty(exec, entry.key.get()))
-                return createSyntaxError(exec, makeString("Can't create duplicate variable that shadows a global property: '", String(entry.key.get()), "'"));
-
+            if (globalObject->hasProperty(exec, entry.key.get())) {
+                // The ES6 spec says that just RestrictedGlobalProperty can't be shadowed
+                // This carried out section 8.1.1.4.14 of the ES6 spec: http://www.ecma-international.org/ecma-262/6.0/index.html#sec-hasrestrictedglobalproperty
+                PropertyDescriptor descriptor;
+                globalObject->getOwnPropertyDescriptor(exec, entry.key.get(), descriptor);
+                
+                if (descriptor.value() != jsUndefined() && !descriptor.configurable())
+                    return createSyntaxError(exec, makeString("Can't create duplicate variable that shadows a global property: '", String(entry.key.get()), "'"));
+            }
+                
             if (globalLexicalEnvironment->hasProperty(exec, entry.key.get())) {
                 if (UNLIKELY(entry.value.isConst() && !vm.globalConstRedeclarationShouldThrow() && !isStrictMode())) {
                     // We only allow "const" duplicate declarations under this setting.

Modified: trunk/Source/_javascript_Core/tests/stress/global-lexical-redeclare-variable.js (202733 => 202734)


--- trunk/Source/_javascript_Core/tests/stress/global-lexical-redeclare-variable.js	2016-07-01 12:46:58 UTC (rev 202733)
+++ trunk/Source/_javascript_Core/tests/stress/global-lexical-redeclare-variable.js	2016-07-01 15:25:35 UTC (rev 202734)
@@ -64,11 +64,52 @@
 }
 assertExpectations();
 
+// Checking if the implementation is following
+// ES6 spec 8.1.1.4.14 http://www.ecma-international.org/ecma-262/6.0/index.html#sec-hasrestrictedglobalproperty
+
 try {
+    sentinel = "bad";
+    assert(Object.getOwnPropertyDescriptor(this, "globalProperty").configurable);
     load("./multiple-files-tests/global-lexical-redeclare-variable/sixth.js");
 } catch(e) {
+    assert(false);
+}
+assertExpectations();
+
+try {
+    sentinel = "bad";
+    assert(Object.getOwnPropertyDescriptor(this, "Array").configurable);
+    load("./multiple-files-tests/global-lexical-redeclare-variable/seventh.js");
+} catch(e) {
+    assert(false);
+}
+assertExpectations();
+
+try {
+    sentinel = "bad";
+    Object.defineProperty(this, 'foo', {value: 5, configurable: true, writable: true});
+    load("./multiple-files-tests/global-lexical-redeclare-variable/eighth.js");
+} catch(e) {
+    assert(false);
+}
+assertExpectations();
+
+try {
+    Object.defineProperty(this, 'bar', {value: 5, configurable: false, writable: true});
+    load("./multiple-files-tests/global-lexical-redeclare-variable/ninth.js");
+} catch(e) {
     assertProperError(e);
 }
 assertExpectations();
 
 assert(errorCount === 6);
+
+try {
+    sentinel = "bad";
+    Object.defineProperty(this, 'zoo', {value: undefined, configurable: false, writable: true});
+    load("./multiple-files-tests/global-lexical-redeclare-variable/tenth.js");
+} catch(e) {
+    assert(false);
+}
+assertExpectations();
+

Added: trunk/Source/_javascript_Core/tests/stress/multiple-files-tests/global-lexical-redeclare-variable/eighth.js (0 => 202734)


--- trunk/Source/_javascript_Core/tests/stress/multiple-files-tests/global-lexical-redeclare-variable/eighth.js	                        (rev 0)
+++ trunk/Source/_javascript_Core/tests/stress/multiple-files-tests/global-lexical-redeclare-variable/eighth.js	2016-07-01 15:25:35 UTC (rev 202734)
@@ -0,0 +1,2 @@
+let foo = 10;
+sentinel = "__s__";

Added: trunk/Source/_javascript_Core/tests/stress/multiple-files-tests/global-lexical-redeclare-variable/ninth.js (0 => 202734)


--- trunk/Source/_javascript_Core/tests/stress/multiple-files-tests/global-lexical-redeclare-variable/ninth.js	                        (rev 0)
+++ trunk/Source/_javascript_Core/tests/stress/multiple-files-tests/global-lexical-redeclare-variable/ninth.js	2016-07-01 15:25:35 UTC (rev 202734)
@@ -0,0 +1,2 @@
+let bar = 10;
+sentinel = "__s__";

Added: trunk/Source/_javascript_Core/tests/stress/multiple-files-tests/global-lexical-redeclare-variable/seventh.js (0 => 202734)


--- trunk/Source/_javascript_Core/tests/stress/multiple-files-tests/global-lexical-redeclare-variable/seventh.js	                        (rev 0)
+++ trunk/Source/_javascript_Core/tests/stress/multiple-files-tests/global-lexical-redeclare-variable/seventh.js	2016-07-01 15:25:35 UTC (rev 202734)
@@ -0,0 +1,2 @@
+let Array = 2;
+sentinel = "__s__";

Modified: trunk/Source/_javascript_Core/tests/stress/multiple-files-tests/global-lexical-redeclare-variable/sixth.js (202733 => 202734)


--- trunk/Source/_javascript_Core/tests/stress/multiple-files-tests/global-lexical-redeclare-variable/sixth.js	2016-07-01 12:46:58 UTC (rev 202733)
+++ trunk/Source/_javascript_Core/tests/stress/multiple-files-tests/global-lexical-redeclare-variable/sixth.js	2016-07-01 15:25:35 UTC (rev 202734)
@@ -1,2 +1,2 @@
-let globalProperty = "bad";
-sentinel = "bad";
+let globalProperty = "good";
+sentinel = "__s__";

Added: trunk/Source/_javascript_Core/tests/stress/multiple-files-tests/global-lexical-redeclare-variable/tenth.js (0 => 202734)


--- trunk/Source/_javascript_Core/tests/stress/multiple-files-tests/global-lexical-redeclare-variable/tenth.js	                        (rev 0)
+++ trunk/Source/_javascript_Core/tests/stress/multiple-files-tests/global-lexical-redeclare-variable/tenth.js	2016-07-01 15:25:35 UTC (rev 202734)
@@ -0,0 +1,2 @@
+let zoo = 2;
+sentinel = "__s__";
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to