Title: [259835] trunk
Revision
259835
Author
ysuz...@apple.com
Date
2020-04-09 15:49:01 -0700 (Thu, 09 Apr 2020)

Log Message

[JSC] ModuleEnvironment do not have JSGlobalLexicalEnvironment as its upper scope
https://bugs.webkit.org/show_bug.cgi?id=193347

Reviewed by Tadeu Zagallo.

JSTests:

* stress/global-lexical-environment-access-from-module.js: Added.
(shouldBe):
(import.string_appeared_here.then):
* stress/resources/global-lexical-environment-access-from-module-child.js: Added.
(export.read):
(export.write):

LayoutTests/imported/w3c:

* web-platform-tests/html/semantics/scripting-1/the-script-element/module/inline-async-execorder-expected.txt:

Source/_javascript_Core:

The upper scope of module scope should be global lexical environment instead of global object.
This patch fixes it to allow modules to access global lexical environment's variables.

* bytecode/CodeBlock.cpp:
(JSC::CodeBlock::notifyLexicalBindingUpdate):
* dfg/DFGByteCodeParser.cpp:
(JSC::DFG::ByteCodeParser::parseBlock):
* runtime/JSModuleEnvironment.h:
* runtime/JSModuleRecord.cpp:
(JSC::JSModuleRecord::instantiateDeclarations):

Modified Paths

Added Paths

Diff

Modified: trunk/JSTests/ChangeLog (259834 => 259835)


--- trunk/JSTests/ChangeLog	2020-04-09 22:17:29 UTC (rev 259834)
+++ trunk/JSTests/ChangeLog	2020-04-09 22:49:01 UTC (rev 259835)
@@ -1,5 +1,19 @@
 2020-04-09  Yusuke Suzuki  <ysuz...@apple.com>
 
+        [JSC] ModuleEnvironment do not have JSGlobalLexicalEnvironment as its upper scope
+        https://bugs.webkit.org/show_bug.cgi?id=193347
+
+        Reviewed by Tadeu Zagallo.
+
+        * stress/global-lexical-environment-access-from-module.js: Added.
+        (shouldBe):
+        (import.string_appeared_here.then):
+        * stress/resources/global-lexical-environment-access-from-module-child.js: Added.
+        (export.read):
+        (export.write):
+
+2020-04-09  Yusuke Suzuki  <ysuz...@apple.com>
+
         Unreviewed, skip JSTests/stress/intl-canonicalize-locale-list-error-oom.js if memoryLimited
         <rdar://problem/61533598>
 

Added: trunk/JSTests/stress/global-lexical-environment-access-from-module.js (0 => 259835)


--- trunk/JSTests/stress/global-lexical-environment-access-from-module.js	                        (rev 0)
+++ trunk/JSTests/stress/global-lexical-environment-access-from-module.js	2020-04-09 22:49:01 UTC (rev 259835)
@@ -0,0 +1,12 @@
+function shouldBe(actual, expected) {
+    if (actual !== expected)
+        throw new Error('bad value: ' + actual);
+}
+
+let test = 42;
+import("./resources/global-lexical-environment-access-from-module-child.js").then(function (namespace) {
+    shouldBe(namespace.read(), 42);
+    namespace.write(50);
+    shouldBe(namespace.read(), 50);
+    shouldBe(test, 50);
+}).catch($vm.abort);

Added: trunk/JSTests/stress/resources/global-lexical-environment-access-from-module-child.js (0 => 259835)


--- trunk/JSTests/stress/resources/global-lexical-environment-access-from-module-child.js	                        (rev 0)
+++ trunk/JSTests/stress/resources/global-lexical-environment-access-from-module-child.js	2020-04-09 22:49:01 UTC (rev 259835)
@@ -0,0 +1,7 @@
+export function read() {
+    return test;
+}
+
+export function write(value) {
+    test = value;
+}

Modified: trunk/LayoutTests/imported/w3c/ChangeLog (259834 => 259835)


--- trunk/LayoutTests/imported/w3c/ChangeLog	2020-04-09 22:17:29 UTC (rev 259834)
+++ trunk/LayoutTests/imported/w3c/ChangeLog	2020-04-09 22:49:01 UTC (rev 259835)
@@ -1,3 +1,12 @@
+2020-04-09  Yusuke Suzuki  <ysuz...@apple.com>
+
+        [JSC] ModuleEnvironment do not have JSGlobalLexicalEnvironment as its upper scope
+        https://bugs.webkit.org/show_bug.cgi?id=193347
+
+        Reviewed by Tadeu Zagallo.
+
+        * web-platform-tests/html/semantics/scripting-1/the-script-element/module/inline-async-execorder-expected.txt:
+
 2020-04-08  Chris Dumez  <cdu...@apple.com>
 
         querySelector("#\u0000") should match an element with ID U+FFFD

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/module/inline-async-execorder-expected.txt (259834 => 259835)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/module/inline-async-execorder-expected.txt	2020-04-09 22:17:29 UTC (rev 259834)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/module/inline-async-execorder-expected.txt	2020-04-09 22:49:01 UTC (rev 259835)
@@ -1,9 +1,3 @@
-CONSOLE MESSAGE: line 1: ReferenceError: Can't find variable: loaded
-CONSOLE MESSAGE: line 1: ReferenceError: Can't find variable: loaded
-CONSOLE MESSAGE: line 3: ReferenceError: Can't find variable: loaded
-CONSOLE MESSAGE: line 3: ReferenceError: Can't find variable: loaded
 
-Harness Error (FAIL), message = ReferenceError: Can't find variable: loaded
+PASS Inline async module script execution order 
 
-FAIL Inline async module script execution order assert_array_equals: lengths differ, expected 6 got 0
-

Modified: trunk/Source/_javascript_Core/ChangeLog (259834 => 259835)


--- trunk/Source/_javascript_Core/ChangeLog	2020-04-09 22:17:29 UTC (rev 259834)
+++ trunk/Source/_javascript_Core/ChangeLog	2020-04-09 22:49:01 UTC (rev 259835)
@@ -1,3 +1,21 @@
+2020-04-09  Yusuke Suzuki  <ysuz...@apple.com>
+
+        [JSC] ModuleEnvironment do not have JSGlobalLexicalEnvironment as its upper scope
+        https://bugs.webkit.org/show_bug.cgi?id=193347
+
+        Reviewed by Tadeu Zagallo.
+
+        The upper scope of module scope should be global lexical environment instead of global object.
+        This patch fixes it to allow modules to access global lexical environment's variables.
+
+        * bytecode/CodeBlock.cpp:
+        (JSC::CodeBlock::notifyLexicalBindingUpdate):
+        * dfg/DFGByteCodeParser.cpp:
+        (JSC::DFG::ByteCodeParser::parseBlock):
+        * runtime/JSModuleEnvironment.h:
+        * runtime/JSModuleRecord.cpp:
+        (JSC::JSModuleRecord::instantiateDeclarations):
+
 2020-04-09  Alexey Shvayka  <shvaikal...@gmail.com>
 
         ProxyObject::defineOwnProperty() should conditionally throw on falsy trap result

Modified: trunk/Source/_javascript_Core/bytecode/CodeBlock.cpp (259834 => 259835)


--- trunk/Source/_javascript_Core/bytecode/CodeBlock.cpp	2020-04-09 22:17:29 UTC (rev 259834)
+++ trunk/Source/_javascript_Core/bytecode/CodeBlock.cpp	2020-04-09 22:49:01 UTC (rev 259835)
@@ -2884,10 +2884,6 @@
 
 void CodeBlock::notifyLexicalBindingUpdate()
 {
-    // FIXME: Currently, module code do not query to JSGlobalLexicalEnvironment. So this case should be removed once it is fixed.
-    // https://bugs.webkit.org/show_bug.cgi?id=193347
-    if (scriptMode() == JSParserScriptMode::Module)
-        return;
     JSGlobalObject* globalObject = m_globalObject.get();
     JSGlobalLexicalEnvironment* globalLexicalEnvironment = jsCast<JSGlobalLexicalEnvironment*>(globalObject->globalScope());
     SymbolTable* symbolTable = globalLexicalEnvironment->symbolTable();

Modified: trunk/Source/_javascript_Core/dfg/DFGByteCodeParser.cpp (259834 => 259835)


--- trunk/Source/_javascript_Core/dfg/DFGByteCodeParser.cpp	2020-04-09 22:17:29 UTC (rev 259834)
+++ trunk/Source/_javascript_Core/dfg/DFGByteCodeParser.cpp	2020-04-09 22:49:01 UTC (rev 259835)
@@ -6677,15 +6677,11 @@
             if (needsVarInjectionChecks(resolveType))
                 m_graph.watchpoints().addLazily(m_inlineStackTop->m_codeBlock->globalObject()->varInjectionWatchpoint());
 
-            // FIXME: Currently, module code do not query to JSGlobalLexicalEnvironment. So this case should be removed once it is fixed.
-            // https://bugs.webkit.org/show_bug.cgi?id=193347
-            if (m_inlineStackTop->m_codeBlock->scriptMode() != JSParserScriptMode::Module) {
-                if (resolveType == GlobalProperty || resolveType == GlobalPropertyWithVarInjectionChecks) {
-                    JSGlobalObject* globalObject = m_inlineStackTop->m_codeBlock->globalObject();
-                    unsigned identifierNumber = m_inlineStackTop->m_identifierRemap[bytecode.m_var];
-                    if (!m_graph.watchGlobalProperty(globalObject, identifierNumber))
-                        addToGraph(ForceOSRExit);
-                }
+            if (resolveType == GlobalProperty || resolveType == GlobalPropertyWithVarInjectionChecks) {
+                JSGlobalObject* globalObject = m_inlineStackTop->m_codeBlock->globalObject();
+                unsigned identifierNumber = m_inlineStackTop->m_identifierRemap[bytecode.m_var];
+                if (!m_graph.watchGlobalProperty(globalObject, identifierNumber))
+                    addToGraph(ForceOSRExit);
             }
 
             switch (resolveType) {
@@ -6793,12 +6789,8 @@
             switch (resolveType) {
             case GlobalProperty:
             case GlobalPropertyWithVarInjectionChecks: {
-                // FIXME: Currently, module code do not query to JSGlobalLexicalEnvironment. So this case should be removed once it is fixed.
-                // https://bugs.webkit.org/show_bug.cgi?id=193347
-                if (m_inlineStackTop->m_codeBlock->scriptMode() != JSParserScriptMode::Module) {
-                    if (!m_graph.watchGlobalProperty(globalObject, identifierNumber))
-                        addToGraph(ForceOSRExit);
-                }
+                if (!m_graph.watchGlobalProperty(globalObject, identifierNumber))
+                    addToGraph(ForceOSRExit);
 
                 SpeculatedType prediction = getPrediction();
 
@@ -6970,12 +6962,8 @@
             switch (resolveType) {
             case GlobalProperty:
             case GlobalPropertyWithVarInjectionChecks: {
-                // FIXME: Currently, module code do not query to JSGlobalLexicalEnvironment. So this case should be removed once it is fixed.
-                // https://bugs.webkit.org/show_bug.cgi?id=193347
-                if (m_inlineStackTop->m_codeBlock->scriptMode() != JSParserScriptMode::Module) {
-                    if (!m_graph.watchGlobalProperty(globalObject, identifierNumber))
-                        addToGraph(ForceOSRExit);
-                }
+                if (!m_graph.watchGlobalProperty(globalObject, identifierNumber))
+                    addToGraph(ForceOSRExit);
 
                 PutByIdStatus status;
                 if (uid)

Modified: trunk/Source/_javascript_Core/runtime/JSModuleEnvironment.h (259834 => 259835)


--- trunk/Source/_javascript_Core/runtime/JSModuleEnvironment.h	2020-04-09 22:17:29 UTC (rev 259834)
+++ trunk/Source/_javascript_Core/runtime/JSModuleEnvironment.h	2020-04-09 22:49:01 UTC (rev 259835)
@@ -42,8 +42,6 @@
     using Base = JSLexicalEnvironment;
     static constexpr unsigned StructureFlags = Base::StructureFlags | OverridesGetOwnPropertySlot | OverridesGetPropertyNames;
 
-    static JSModuleEnvironment* create(VM&, Structure*, JSScope*, SymbolTable*, JSValue initialValue, AbstractModuleRecord*);
-
     static JSModuleEnvironment* create(VM& vm, JSGlobalObject* globalObject, JSScope* currentScope, SymbolTable* symbolTable, JSValue initialValue, AbstractModuleRecord* moduleRecord)
     {
         Structure* structure = globalObject->moduleEnvironmentStructure();
@@ -82,6 +80,8 @@
 private:
     JSModuleEnvironment(VM&, Structure*, JSScope*, SymbolTable*);
 
+    static JSModuleEnvironment* create(VM&, Structure*, JSScope*, SymbolTable*, JSValue initialValue, AbstractModuleRecord*);
+
     void finishCreation(VM&, JSValue initialValue, AbstractModuleRecord*);
 
     WriteBarrierBase<AbstractModuleRecord>& moduleRecordSlot()

Modified: trunk/Source/_javascript_Core/runtime/JSModuleRecord.cpp (259834 => 259835)


--- trunk/Source/_javascript_Core/runtime/JSModuleRecord.cpp	2020-04-09 22:17:29 UTC (rev 259834)
+++ trunk/Source/_javascript_Core/runtime/JSModuleRecord.cpp	2020-04-09 22:49:01 UTC (rev 259835)
@@ -103,7 +103,7 @@
     // http://www.ecma-international.org/ecma-262/6.0/#sec-moduledeclarationinstantiation
 
     SymbolTable* symbolTable = moduleProgramExecutable->moduleEnvironmentSymbolTable();
-    JSModuleEnvironment* moduleEnvironment = JSModuleEnvironment::create(vm, globalObject, globalObject, symbolTable, jsTDZValue(), this);
+    JSModuleEnvironment* moduleEnvironment = JSModuleEnvironment::create(vm, globalObject, globalObject->globalLexicalEnvironment(), symbolTable, jsTDZValue(), this);
 
     // http://www.ecma-international.org/ecma-262/6.0/#sec-moduledeclarationinstantiation
     // section 15.2.1.16.4 step 9.
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to