Title: [210573] trunk
Revision
210573
Author
[email protected]
Date
2017-01-10 18:26:47 -0800 (Tue, 10 Jan 2017)

Log Message

Implement JSSourceCode to propagate SourceCode in module pipeline
https://bugs.webkit.org/show_bug.cgi?id=166861

Reviewed by Saam Barati.

Source/_javascript_Core:

Instead of propagating source code string, we propagate JSSourceCode
cell in the module pipeline. This allows us to attach a metadata
to the propagated source code string. In particular, it propagates
SourceOrigin through the module pipeline.

And it also fixes JSC shell to use Module source type for module source code.

* CMakeLists.txt:
* _javascript_Core.xcodeproj/project.pbxproj:
* builtins/ModuleLoaderPrototype.js:
(fulfillFetch):
(requestFetch):
* jsc.cpp:
(GlobalObject::moduleLoaderFetch):
(runWithScripts):
* llint/LLIntData.cpp:
(JSC::LLInt::Data::performAssertions):
* llint/LowLevelInterpreter.asm:
* runtime/Completion.cpp:
(JSC::loadAndEvaluateModule):
(JSC::loadModule):
* runtime/JSModuleLoader.cpp:
(JSC::JSModuleLoader::provide):
* runtime/JSModuleLoader.h:
* runtime/JSSourceCode.cpp: Added.
(JSC::JSSourceCode::destroy):
* runtime/JSSourceCode.h: Added.
(JSC::JSSourceCode::createStructure):
(JSC::JSSourceCode::create):
(JSC::JSSourceCode::sourceCode):
(JSC::JSSourceCode::JSSourceCode):
* runtime/JSType.h:
* runtime/ModuleLoaderPrototype.cpp:
(JSC::moduleLoaderPrototypeParseModule):
* runtime/VM.cpp:
(JSC::VM::VM):
* runtime/VM.h:

Source/WebCore:

Now SourceOrigin is correctly propagated through the module pipeline.
So the error reported by http/tests/security/contentSecurityPolicy/module-eval-blocked-expected.html
is updated.

* ForwardingHeaders/runtime/JSSourceCode.h: Added.
* bindings/js/JSDOMPromise.h:
(WebCore::DeferredPromise::resolveWithCallback):
* bindings/js/ScriptModuleLoader.cpp:
(WebCore::ScriptModuleLoader::notifyFinished):

LayoutTests:

* http/tests/security/contentSecurityPolicy/module-eval-blocked-expected.txt:

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (210572 => 210573)


--- trunk/LayoutTests/ChangeLog	2017-01-11 01:54:25 UTC (rev 210572)
+++ trunk/LayoutTests/ChangeLog	2017-01-11 02:26:47 UTC (rev 210573)
@@ -1,3 +1,12 @@
+2017-01-10  Yusuke Suzuki  <[email protected]>
+
+        Implement JSSourceCode to propagate SourceCode in module pipeline
+        https://bugs.webkit.org/show_bug.cgi?id=166861
+
+        Reviewed by Saam Barati.
+
+        * http/tests/security/contentSecurityPolicy/module-eval-blocked-expected.txt:
+
 2017-01-10  Commit Queue  <[email protected]>
 
         Unreviewed, rolling out r210052.

Modified: trunk/LayoutTests/http/tests/security/contentSecurityPolicy/module-eval-blocked-expected.txt (210572 => 210573)


--- trunk/LayoutTests/http/tests/security/contentSecurityPolicy/module-eval-blocked-expected.txt	2017-01-11 01:54:25 UTC (rev 210572)
+++ trunk/LayoutTests/http/tests/security/contentSecurityPolicy/module-eval-blocked-expected.txt	2017-01-11 02:26:47 UTC (rev 210573)
@@ -1,37 +1,37 @@
-CONSOLE MESSAGE: line 1: EvalError: Refused to evaluate a string as _javascript_ because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: "script-src 'unsafe-inline'".
+CONSOLE MESSAGE: line 16: EvalError: Refused to evaluate a string as _javascript_ because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: "script-src 'unsafe-inline'".
 
-CONSOLE MESSAGE: line 1: EvalError: Refused to evaluate a string as _javascript_ because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: "script-src 'unsafe-inline'".
+CONSOLE MESSAGE: line 17: EvalError: Refused to evaluate a string as _javascript_ because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: "script-src 'unsafe-inline'".
 
-CONSOLE MESSAGE: line 1: EvalError: Refused to evaluate a string as _javascript_ because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: "script-src 'unsafe-inline'".
+CONSOLE MESSAGE: line 34: EvalError: Refused to evaluate a string as _javascript_ because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: "script-src 'unsafe-inline'".
 
-CONSOLE MESSAGE: line 1: EvalError: Refused to evaluate a string as _javascript_ because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: "script-src 'unsafe-inline'".
+CONSOLE MESSAGE: line 35: EvalError: Refused to evaluate a string as _javascript_ because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: "script-src 'unsafe-inline'".
 
-CONSOLE MESSAGE: line 1: EvalError: Refused to evaluate a string as _javascript_ because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: "script-src 'unsafe-inline'".
+CONSOLE MESSAGE: line 36: EvalError: Refused to evaluate a string as _javascript_ because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: "script-src 'unsafe-inline'".
 
-CONSOLE MESSAGE: line 1: EvalError: Refused to evaluate a string as _javascript_ because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: "script-src 'unsafe-inline'".
+CONSOLE MESSAGE: line 37: EvalError: Refused to evaluate a string as _javascript_ because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: "script-src 'unsafe-inline'".
 
-CONSOLE MESSAGE: line 1: EvalError: Refused to evaluate a string as _javascript_ because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: "script-src 'unsafe-inline'".
+CONSOLE MESSAGE: line 38: EvalError: Refused to evaluate a string as _javascript_ because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: "script-src 'unsafe-inline'".
 
-CONSOLE MESSAGE: line 1: EvalError: Refused to evaluate a string as _javascript_ because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: "script-src 'unsafe-inline'".
+CONSOLE MESSAGE: line 39: EvalError: Refused to evaluate a string as _javascript_ because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: "script-src 'unsafe-inline'".
 
-CONSOLE MESSAGE: line 1: EvalError: Refused to evaluate a string as _javascript_ because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: "script-src 'unsafe-inline'".
+CONSOLE MESSAGE: line 40: EvalError: Refused to evaluate a string as _javascript_ because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: "script-src 'unsafe-inline'".
 
-CONSOLE MESSAGE: line 1: EvalError: Refused to evaluate a string as _javascript_ because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: "script-src 'unsafe-inline'".
+CONSOLE MESSAGE: line 41: EvalError: Refused to evaluate a string as _javascript_ because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: "script-src 'unsafe-inline'".
 
-CONSOLE MESSAGE: line 1: EvalError: Refused to evaluate a string as _javascript_ because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: "script-src 'unsafe-inline'".
+CONSOLE MESSAGE: line 42: EvalError: Refused to evaluate a string as _javascript_ because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: "script-src 'unsafe-inline'".
 
-CONSOLE MESSAGE: line 1: EvalError: Refused to evaluate a string as _javascript_ because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: "script-src 'unsafe-inline'".
+CONSOLE MESSAGE: line 43: EvalError: Refused to evaluate a string as _javascript_ because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: "script-src 'unsafe-inline'".
 
-CONSOLE MESSAGE: line 1: EvalError: Refused to evaluate a string as _javascript_ because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: "script-src 'unsafe-inline'".
+CONSOLE MESSAGE: line 44: EvalError: Refused to evaluate a string as _javascript_ because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: "script-src 'unsafe-inline'".
 
-CONSOLE MESSAGE: line 1: EvalError: Refused to evaluate a string as _javascript_ because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: "script-src 'unsafe-inline'".
+CONSOLE MESSAGE: line 45: EvalError: Refused to evaluate a string as _javascript_ because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: "script-src 'unsafe-inline'".
 
-CONSOLE MESSAGE: line 1: EvalError: Refused to evaluate a string as _javascript_ because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: "script-src 'unsafe-inline'".
+CONSOLE MESSAGE: line 46: EvalError: Refused to evaluate a string as _javascript_ because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: "script-src 'unsafe-inline'".
 
-CONSOLE MESSAGE: line 1: EvalError: Refused to evaluate a string as _javascript_ because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: "script-src 'unsafe-inline'".
+CONSOLE MESSAGE: line 47: EvalError: Refused to evaluate a string as _javascript_ because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: "script-src 'unsafe-inline'".
 
-CONSOLE MESSAGE: line 1: EvalError: Refused to evaluate a string as _javascript_ because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: "script-src 'unsafe-inline'".
+CONSOLE MESSAGE: line 48: EvalError: Refused to evaluate a string as _javascript_ because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: "script-src 'unsafe-inline'".
 
-CONSOLE MESSAGE: line 1: EvalError: Refused to evaluate a string as _javascript_ because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: "script-src 'unsafe-inline'".
+CONSOLE MESSAGE: line 49: EvalError: Refused to evaluate a string as _javascript_ because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: "script-src 'unsafe-inline'".
 
 

Modified: trunk/Source/_javascript_Core/CMakeLists.txt (210572 => 210573)


--- trunk/Source/_javascript_Core/CMakeLists.txt	2017-01-11 01:54:25 UTC (rev 210572)
+++ trunk/Source/_javascript_Core/CMakeLists.txt	2017-01-11 02:26:47 UTC (rev 210573)
@@ -787,6 +787,7 @@
     runtime/JSSegmentedVariableObject.cpp
     runtime/JSSet.cpp
     runtime/JSSetIterator.cpp
+    runtime/JSSourceCode.cpp
     runtime/JSString.cpp
     runtime/JSStringIterator.cpp
     runtime/JSStringJoiner.cpp

Modified: trunk/Source/_javascript_Core/ChangeLog (210572 => 210573)


--- trunk/Source/_javascript_Core/ChangeLog	2017-01-11 01:54:25 UTC (rev 210572)
+++ trunk/Source/_javascript_Core/ChangeLog	2017-01-11 02:26:47 UTC (rev 210573)
@@ -1,3 +1,48 @@
+2017-01-10  Yusuke Suzuki  <[email protected]>
+
+        Implement JSSourceCode to propagate SourceCode in module pipeline
+        https://bugs.webkit.org/show_bug.cgi?id=166861
+
+        Reviewed by Saam Barati.
+
+        Instead of propagating source code string, we propagate JSSourceCode
+        cell in the module pipeline. This allows us to attach a metadata
+        to the propagated source code string. In particular, it propagates
+        SourceOrigin through the module pipeline.
+
+        And it also fixes JSC shell to use Module source type for module source code.
+
+        * CMakeLists.txt:
+        * _javascript_Core.xcodeproj/project.pbxproj:
+        * builtins/ModuleLoaderPrototype.js:
+        (fulfillFetch):
+        (requestFetch):
+        * jsc.cpp:
+        (GlobalObject::moduleLoaderFetch):
+        (runWithScripts):
+        * llint/LLIntData.cpp:
+        (JSC::LLInt::Data::performAssertions):
+        * llint/LowLevelInterpreter.asm:
+        * runtime/Completion.cpp:
+        (JSC::loadAndEvaluateModule):
+        (JSC::loadModule):
+        * runtime/JSModuleLoader.cpp:
+        (JSC::JSModuleLoader::provide):
+        * runtime/JSModuleLoader.h:
+        * runtime/JSSourceCode.cpp: Added.
+        (JSC::JSSourceCode::destroy):
+        * runtime/JSSourceCode.h: Added.
+        (JSC::JSSourceCode::createStructure):
+        (JSC::JSSourceCode::create):
+        (JSC::JSSourceCode::sourceCode):
+        (JSC::JSSourceCode::JSSourceCode):
+        * runtime/JSType.h:
+        * runtime/ModuleLoaderPrototype.cpp:
+        (JSC::moduleLoaderPrototypeParseModule):
+        * runtime/VM.cpp:
+        (JSC::VM::VM):
+        * runtime/VM.h:
+
 2017-01-10  Commit Queue  <[email protected]>
 
         Unreviewed, rolling out r210052.

Modified: trunk/Source/_javascript_Core/_javascript_Core.xcodeproj/project.pbxproj (210572 => 210573)


--- trunk/Source/_javascript_Core/_javascript_Core.xcodeproj/project.pbxproj	2017-01-11 01:54:25 UTC (rev 210572)
+++ trunk/Source/_javascript_Core/_javascript_Core.xcodeproj/project.pbxproj	2017-01-11 02:26:47 UTC (rev 210573)
@@ -2370,6 +2370,8 @@
 		FED94F2F171E3E2300BE77A4 /* Watchdog.h in Headers */ = {isa = PBXBuildFile; fileRef = FED94F2C171E3E2300BE77A4 /* Watchdog.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		FEF040511AAE662D00BD28B0 /* CompareAndSwapTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FEF040501AAE662D00BD28B0 /* CompareAndSwapTest.cpp */; };
 		FEFD6FC61D5E7992008F2F0B /* JSStringInlines.h in Headers */ = {isa = PBXBuildFile; fileRef = FEFD6FC51D5E7970008F2F0B /* JSStringInlines.h */; settings = {ATTRIBUTES = (Private, ); }; };
+		FA3AB211C8494524AB390267 /* JSSourceCode.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F73926918DC64330AFCDF0D7 /* JSSourceCode.cpp */; };
+		BDFCB2BBE90F41349E1B0BED /* JSSourceCode.h in Headers */ = {isa = PBXBuildFile; fileRef = 3032175DF1AD47D8998B34E1 /* JSSourceCode.h */; settings = {ATTRIBUTES = (Private, ); }; };
 /* End PBXBuildFile section */
 
 /* Begin PBXContainerItemProxy section */
@@ -4896,6 +4898,8 @@
 		FEF040501AAE662D00BD28B0 /* CompareAndSwapTest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CompareAndSwapTest.cpp; path = API/tests/CompareAndSwapTest.cpp; sourceTree = "<group>"; };
 		FEF040521AAEC4ED00BD28B0 /* CompareAndSwapTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CompareAndSwapTest.h; path = API/tests/CompareAndSwapTest.h; sourceTree = "<group>"; };
 		FEFD6FC51D5E7970008F2F0B /* JSStringInlines.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSStringInlines.h; sourceTree = "<group>"; };
+		F73926918DC64330AFCDF0D7 /* JSSourceCode.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = JSSourceCode.cpp; path = JSSourceCode.cpp; sourceTree = "<group>"; };
+		3032175DF1AD47D8998B34E1 /* JSSourceCode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = JSSourceCode.h; path = JSSourceCode.h; sourceTree = "<group>"; };
 /* End PBXFileReference section */
 
 /* Begin PBXFrameworksBuildPhase section */
@@ -6734,6 +6738,8 @@
 				A7DCB77912E3D90500911940 /* WriteBarrier.h */,
 				C2B6D75218A33793004A9301 /* WriteBarrierInlines.h */,
 				425BA1337E4344E1B269A671 /* SourceOrigin.h */,
+				F73926918DC64330AFCDF0D7 /* JSSourceCode.cpp */,
+				3032175DF1AD47D8998B34E1 /* JSSourceCode.h */,
 			);
 			path = runtime;
 			sourceTree = "<group>";
@@ -9107,6 +9113,7 @@
 				86704B8A12DBA33700A9FE7B /* YarrPattern.h in Headers */,
 				86704B4312DB8A8100A9FE7B /* YarrSyntaxChecker.h in Headers */,
 				2D342F36F7244096804ADB24 /* SourceOrigin.h in Headers */,
+				BDFCB2BBE90F41349E1B0BED /* JSSourceCode.h in Headers */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
@@ -10494,6 +10501,7 @@
 				86704B8612DBA33700A9FE7B /* YarrJIT.cpp in Sources */,
 				86704B8912DBA33700A9FE7B /* YarrPattern.cpp in Sources */,
 				86704B4212DB8A8100A9FE7B /* YarrSyntaxChecker.cpp in Sources */,
+				FA3AB211C8494524AB390267 /* JSSourceCode.cpp in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};

Modified: trunk/Source/_javascript_Core/builtins/ModuleLoaderPrototype.js (210572 => 210573)


--- trunk/Source/_javascript_Core/builtins/ModuleLoaderPrototype.js	2017-01-11 01:54:25 UTC (rev 210572)
+++ trunk/Source/_javascript_Core/builtins/ModuleLoaderPrototype.js	2017-01-11 02:26:47 UTC (rev 210573)
@@ -127,7 +127,7 @@
         @fulfillPromise(promise, value);
 }
 
-function fulfillFetch(entry, payload)
+function fulfillFetch(entry, source)
 {
     // https://whatwg.github.io/loader/#fulfill-fetch
 
@@ -135,7 +135,7 @@
 
     if (!entry.fetch)
         entry.fetch = @newPromiseCapability(@InternalPromise).@promise;
-    this.forceFulfillPromise(entry.fetch, payload);
+    this.forceFulfillPromise(entry.fetch, source);
     @setStateToMax(entry, @ModuleInstantiate);
 }
 
@@ -220,9 +220,9 @@
     //     Take the key and fetch the resource actually.
     //     For example, _javascript_Core shell can provide the hook fetching the resource
     //     from the local file system.
-    var fetchPromise = this.fetch(key, initiator).then((payload) => {
+    var fetchPromise = this.fetch(key, initiator).then((source) => {
         @setStateToMax(entry, @ModuleInstantiate);
-        return payload;
+        return source;
     });
     entry.fetch = fetchPromise;
     return fetchPromise;

Modified: trunk/Source/_javascript_Core/jsc.cpp (210572 => 210573)


--- trunk/Source/_javascript_Core/jsc.cpp	2017-01-11 01:54:25 UTC (rev 210572)
+++ trunk/Source/_javascript_Core/jsc.cpp	2017-01-11 02:26:47 UTC (rev 210573)
@@ -53,6 +53,7 @@
 #include "JSNativeStdFunction.h"
 #include "JSONObject.h"
 #include "JSProxy.h"
+#include "JSSourceCode.h"
 #include "JSString.h"
 #include "JSTypedArrays.h"
 #include "JSWebAssemblyCallee.h"
@@ -1576,7 +1577,7 @@
     if (!fetchModuleFromLocalFileSystem(moduleKey, utf8))
         return deferred->reject(exec, createError(exec, makeString("Could not open file '", moduleKey, "'.")));
 
-    return deferred->resolve(exec, jsString(exec, stringFromUTF(utf8)));
+    return deferred->resolve(exec, JSSourceCode::create(exec->vm(), makeSource(stringFromUTF(utf8), SourceOrigin { moduleKey }, moduleKey, TextPosition(), SourceProviderSourceType::Module)));
 }
 
 
@@ -2936,7 +2937,7 @@
         bool isLastFile = i == scripts.size() - 1;
         if (isModule) {
             if (!promise)
-                promise = loadAndEvaluateModule(globalObject->globalExec(), jscSource(scriptBuffer, SourceOrigin { absolutePath(fileName) }, fileName));
+                promise = loadAndEvaluateModule(globalObject->globalExec(), makeSource(stringFromUTF(scriptBuffer), SourceOrigin { absolutePath(fileName) }, fileName, TextPosition(), SourceProviderSourceType::Module));
             scope.clearException();
 
             JSFunction* fulfillHandler = JSNativeStdFunction::create(vm, globalObject, 1, String(), [&, isLastFile](ExecState* exec) {

Modified: trunk/Source/_javascript_Core/llint/LLIntData.cpp (210572 => 210573)


--- trunk/Source/_javascript_Core/llint/LLIntData.cpp	2017-01-11 01:54:25 UTC (rev 210572)
+++ trunk/Source/_javascript_Core/llint/LLIntData.cpp	2017-01-11 02:26:47 UTC (rev 210573)
@@ -156,21 +156,21 @@
     
     STATIC_ASSERT(StringType == 6);
     STATIC_ASSERT(SymbolType == 7);
-    STATIC_ASSERT(ObjectType == 21);
-    STATIC_ASSERT(FinalObjectType == 22);
-    STATIC_ASSERT(JSFunctionType == 24);
-    STATIC_ASSERT(ArrayType == 32);
-    STATIC_ASSERT(DerivedArrayType == 33);
-    STATIC_ASSERT(ProxyObjectType == 51);
-    STATIC_ASSERT(Int8ArrayType == 34);
-    STATIC_ASSERT(Int16ArrayType == 35);
-    STATIC_ASSERT(Int32ArrayType == 36);
-    STATIC_ASSERT(Uint8ArrayType == 37);
-    STATIC_ASSERT(Uint8ClampedArrayType == 38);
-    STATIC_ASSERT(Uint16ArrayType == 39);
-    STATIC_ASSERT(Uint32ArrayType == 40);
-    STATIC_ASSERT(Float32ArrayType == 41);
-    STATIC_ASSERT(Float64ArrayType == 42);
+    STATIC_ASSERT(ObjectType == 22);
+    STATIC_ASSERT(FinalObjectType == 23);
+    STATIC_ASSERT(JSFunctionType == 25);
+    STATIC_ASSERT(ArrayType == 33);
+    STATIC_ASSERT(DerivedArrayType == 34);
+    STATIC_ASSERT(ProxyObjectType == 52);
+    STATIC_ASSERT(Int8ArrayType == 35);
+    STATIC_ASSERT(Int16ArrayType == 36);
+    STATIC_ASSERT(Int32ArrayType == 37);
+    STATIC_ASSERT(Uint8ArrayType == 38);
+    STATIC_ASSERT(Uint8ClampedArrayType == 39);
+    STATIC_ASSERT(Uint16ArrayType == 40);
+    STATIC_ASSERT(Uint32ArrayType == 41);
+    STATIC_ASSERT(Float32ArrayType == 42);
+    STATIC_ASSERT(Float64ArrayType == 43);
     STATIC_ASSERT(MasqueradesAsUndefined == 1);
     STATIC_ASSERT(ImplementsDefaultHasInstance == 2);
     STATIC_ASSERT(FirstConstantRegisterIndex == 0x40000000);

Modified: trunk/Source/_javascript_Core/llint/LowLevelInterpreter.asm (210572 => 210573)


--- trunk/Source/_javascript_Core/llint/LowLevelInterpreter.asm	2017-01-11 01:54:25 UTC (rev 210572)
+++ trunk/Source/_javascript_Core/llint/LowLevelInterpreter.asm	2017-01-11 02:26:47 UTC (rev 210573)
@@ -345,24 +345,24 @@
 # Type constants.
 const StringType = 6
 const SymbolType = 7
-const ObjectType = 21
-const FinalObjectType = 22
-const JSFunctionType = 24
-const ArrayType = 32
-const DerivedArrayType = 33
-const ProxyObjectType = 51
+const ObjectType = 22
+const FinalObjectType = 23
+const JSFunctionType = 25
+const ArrayType = 33
+const DerivedArrayType = 34
+const ProxyObjectType = 52
 
 # The typed array types need to be numbered in a particular order because of the manually written
 # switch statement in get_by_val and put_by_val.
-const Int8ArrayType = 34
-const Int16ArrayType = 35
-const Int32ArrayType = 36
-const Uint8ArrayType = 37
-const Uint8ClampedArrayType = 38
-const Uint16ArrayType = 39
-const Uint32ArrayType = 40
-const Float32ArrayType = 41
-const Float64ArrayType = 42
+const Int8ArrayType = 35
+const Int16ArrayType = 36
+const Int32ArrayType = 37
+const Uint8ArrayType = 38
+const Uint8ClampedArrayType = 39
+const Uint16ArrayType = 40
+const Uint32ArrayType = 41
+const Float32ArrayType = 42
+const Float64ArrayType = 43
 
 const FirstArrayType = Int8ArrayType
 const LastArrayType = Float64ArrayType

Modified: trunk/Source/_javascript_Core/runtime/Completion.cpp (210572 => 210573)


--- trunk/Source/_javascript_Core/runtime/Completion.cpp	2017-01-11 01:54:25 UTC (rev 210572)
+++ trunk/Source/_javascript_Core/runtime/Completion.cpp	2017-01-11 02:26:47 UTC (rev 210573)
@@ -193,7 +193,7 @@
     JSGlobalObject* globalObject = exec->vmEntryGlobalObject();
 
     // Insert the given source code to the ModuleLoader registry as the fetched registry entry.
-    globalObject->moduleLoader()->provide(exec, key, JSModuleLoader::Status::Fetch, source.view().toString());
+    globalObject->moduleLoader()->provide(exec, key, JSModuleLoader::Status::Fetch, source);
     RETURN_IF_EXCEPTION(scope, rejectPromise(exec, globalObject));
 
     return loadAndEvaluateModule(lock, exec, globalObject, key, jsUndefined(), initiator);
@@ -232,7 +232,7 @@
 
     // Insert the given source code to the ModuleLoader registry as the fetched registry entry.
     // FIXME: Introduce JSSourceCode object to wrap around this source.
-    globalObject->moduleLoader()->provide(exec, key, JSModuleLoader::Status::Fetch, source.view().toString());
+    globalObject->moduleLoader()->provide(exec, key, JSModuleLoader::Status::Fetch, source);
     RETURN_IF_EXCEPTION(scope, rejectPromise(exec, globalObject));
 
     return loadModule(lock, exec, globalObject, key, jsUndefined(), initiator);

Modified: trunk/Source/_javascript_Core/runtime/JSModuleLoader.cpp (210572 => 210573)


--- trunk/Source/_javascript_Core/runtime/JSModuleLoader.cpp	2017-01-11 01:54:25 UTC (rev 210572)
+++ trunk/Source/_javascript_Core/runtime/JSModuleLoader.cpp	2017-01-11 02:26:47 UTC (rev 210573)
@@ -38,6 +38,7 @@
 #include "JSMap.h"
 #include "JSModuleEnvironment.h"
 #include "JSModuleRecord.h"
+#include "JSSourceCode.h"
 #include "ModuleAnalyzer.h"
 #include "ModuleLoaderPrototype.h"
 #include "Nodes.h"
@@ -75,17 +76,19 @@
     return exec->propertyNames().emptyIdentifier.impl();
 }
 
-JSValue JSModuleLoader::provide(ExecState* exec, JSValue key, Status status, const String& source)
+JSValue JSModuleLoader::provide(ExecState* exec, JSValue key, Status status, const SourceCode& sourceCode)
 {
+    VM& vm = exec->vm();
     JSObject* function = jsCast<JSObject*>(get(exec, exec->propertyNames().builtinNames().providePublicName()));
     CallData callData;
     CallType callType = JSC::getCallData(function, callData);
     ASSERT(callType != CallType::None);
 
+    SourceCode source { sourceCode };
     MarkedArgumentBuffer arguments;
     arguments.append(key);
     arguments.append(jsNumber(status));
-    arguments.append(jsString(exec, source));
+    arguments.append(JSSourceCode::create(vm, WTFMove(source)));
 
     return call(exec, function, callType, callData, this, arguments);
 }

Modified: trunk/Source/_javascript_Core/runtime/JSModuleLoader.h (210572 => 210573)


--- trunk/Source/_javascript_Core/runtime/JSModuleLoader.h	2017-01-11 01:54:25 UTC (rev 210572)
+++ trunk/Source/_javascript_Core/runtime/JSModuleLoader.h	2017-01-11 02:26:47 UTC (rev 210573)
@@ -32,6 +32,7 @@
 
 class JSInternalPromise;
 class JSModuleNamespaceObject;
+class SourceCode;
 
 class JSModuleLoader : public JSNonFinalObject {
 private:
@@ -62,7 +63,7 @@
     }
 
     // APIs to control the module loader.
-    JSValue provide(ExecState*, JSValue key, Status, const String&);
+    JSValue provide(ExecState*, JSValue key, Status, const SourceCode&);
     JSInternalPromise* loadAndEvaluateModule(ExecState*, JSValue moduleName, JSValue referrer, JSValue initiator);
     JSInternalPromise* loadModule(ExecState*, JSValue moduleName, JSValue referrer, JSValue initiator);
     JSValue linkAndEvaluateModule(ExecState*, JSValue moduleKey, JSValue initiator);

Added: trunk/Source/_javascript_Core/runtime/JSSourceCode.cpp (0 => 210573)


--- trunk/Source/_javascript_Core/runtime/JSSourceCode.cpp	                        (rev 0)
+++ trunk/Source/_javascript_Core/runtime/JSSourceCode.cpp	2017-01-11 02:26:47 UTC (rev 210573)
@@ -0,0 +1,40 @@
+/*
+ * Copyright (C) 2016 Yusuke Suzuki <[email protected]>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "JSSourceCode.h"
+
+#include "JSCInlines.h"
+
+namespace JSC {
+
+const ClassInfo JSSourceCode::s_info = { "JSSourceCode", nullptr, nullptr, CREATE_METHOD_TABLE(JSSourceCode) };
+
+void JSSourceCode::destroy(JSCell* cell)
+{
+    static_cast<JSSourceCode*>(cell)->~JSSourceCode();
+}
+
+} // namespace JSC

Added: trunk/Source/_javascript_Core/runtime/JSSourceCode.h (0 => 210573)


--- trunk/Source/_javascript_Core/runtime/JSSourceCode.h	                        (rev 0)
+++ trunk/Source/_javascript_Core/runtime/JSSourceCode.h	2017-01-11 02:26:47 UTC (rev 210573)
@@ -0,0 +1,77 @@
+/*
+ * Copyright (C) 2016 Yusuke Suzuki <[email protected]>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#include "JSGlobalObject.h"
+#include "JSObject.h"
+#include "SourceCode.h"
+
+namespace JSC {
+
+class JSSourceCode : public JSCell {
+public:
+    using Base = JSCell;
+
+    static const unsigned StructureFlags = Base::StructureFlags | StructureIsImmortal;
+    static const bool needsDestruction = true;
+
+    DECLARE_EXPORT_INFO;
+
+    static Structure* createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype)
+    {
+        return Structure::create(vm, globalObject, prototype, TypeInfo(JSSourceCodeType, StructureFlags), info());
+    }
+
+    static JSSourceCode* create(VM& vm, Structure* structure, SourceCode&& sourceCode)
+    {
+        auto* result = new (NotNull, allocateCell<JSSourceCode>(vm.heap)) JSSourceCode(vm, structure, WTFMove(sourceCode));
+        result->finishCreation(vm);
+        return result;
+    }
+
+    static JSSourceCode* create(VM& vm, SourceCode&& sourceCode)
+    {
+        return create(vm, vm.sourceCodeStructure.get(), WTFMove(sourceCode));
+    }
+
+    const SourceCode& sourceCode() const
+    {
+        return m_sourceCode;
+    }
+
+    static void destroy(JSCell*);
+
+private:
+    JSSourceCode(VM& vm, Structure* structure, SourceCode&& sourceCode)
+        : Base(vm, structure)
+        , m_sourceCode(WTFMove(sourceCode))
+    {
+    }
+
+    SourceCode m_sourceCode;
+};
+
+} // namespace JSC

Modified: trunk/Source/_javascript_Core/runtime/JSType.h (210572 => 210573)


--- trunk/Source/_javascript_Core/runtime/JSType.h	2017-01-11 01:54:25 UTC (rev 210572)
+++ trunk/Source/_javascript_Core/runtime/JSType.h	2017-01-11 02:26:47 UTC (rev 210573)
@@ -50,6 +50,7 @@
     UnlinkedFunctionCodeBlockType,
 
     JSFixedArrayType,
+    JSSourceCodeType,
 
     // The ObjectType value must come before any JSType that is a subclass of JSObject.
     ObjectType,

Modified: trunk/Source/_javascript_Core/runtime/ModuleLoaderPrototype.cpp (210572 => 210573)


--- trunk/Source/_javascript_Core/runtime/ModuleLoaderPrototype.cpp	2017-01-11 01:54:25 UTC (rev 210572)
+++ trunk/Source/_javascript_Core/runtime/ModuleLoaderPrototype.cpp	2017-01-11 02:26:47 UTC (rev 210573)
@@ -39,6 +39,7 @@
 #include "JSModuleLoader.h"
 #include "JSModuleNamespaceObject.h"
 #include "JSModuleRecord.h"
+#include "JSSourceCode.h"
 #include "ModuleAnalyzer.h"
 #include "Nodes.h"
 #include "Parser.h"
@@ -112,11 +113,11 @@
     const Identifier moduleKey = exec->argument(0).toPropertyKey(exec);
     RETURN_IF_EXCEPTION(scope, encodedJSValue());
 
-    String source = exec->argument(1).toWTFString(exec);
-    RETURN_IF_EXCEPTION(scope, encodedJSValue());
+    auto* jsSourceCode = jsDynamicCast<JSSourceCode*>(exec->argument(1));
+    if (!jsSourceCode)
+        return throwVMTypeError(exec, scope);
+    SourceCode sourceCode = jsSourceCode->sourceCode();
 
-    SourceCode sourceCode = makeSource(source, SourceOrigin { moduleKey.impl() }, moduleKey.impl(), TextPosition(), SourceProviderSourceType::Module);
-
     CodeProfiling profile(sourceCode);
 
     ParserError error;

Modified: trunk/Source/_javascript_Core/runtime/VM.cpp (210572 => 210573)


--- trunk/Source/_javascript_Core/runtime/VM.cpp	2017-01-11 01:54:25 UTC (rev 210572)
+++ trunk/Source/_javascript_Core/runtime/VM.cpp	2017-01-11 02:26:47 UTC (rev 210573)
@@ -71,6 +71,7 @@
 #include "JSMap.h"
 #include "JSPromiseDeferred.h"
 #include "JSPropertyNameEnumerator.h"
+#include "JSSourceCode.h"
 #include "JSTemplateRegistryKey.h"
 #include "JSWebAssembly.h"
 #include "JSWithScope.h"
@@ -238,6 +239,7 @@
     symbolStructure.set(*this, Symbol::createStructure(*this, 0, jsNull()));
     symbolTableStructure.set(*this, SymbolTable::createStructure(*this, 0, jsNull()));
     fixedArrayStructure.set(*this, JSFixedArray::createStructure(*this, 0, jsNull()));
+    sourceCodeStructure.set(*this, JSSourceCode::createStructure(*this, 0, jsNull()));
     structureChainStructure.set(*this, StructureChain::createStructure(*this, 0, jsNull()));
     sparseArrayValueMapStructure.set(*this, SparseArrayValueMap::createStructure(*this, 0, jsNull()));
     templateRegistryKeyStructure.set(*this, JSTemplateRegistryKey::createStructure(*this, 0, jsNull()));

Modified: trunk/Source/_javascript_Core/runtime/VM.h (210572 => 210573)


--- trunk/Source/_javascript_Core/runtime/VM.h	2017-01-11 01:54:25 UTC (rev 210572)
+++ trunk/Source/_javascript_Core/runtime/VM.h	2017-01-11 02:26:47 UTC (rev 210573)
@@ -326,6 +326,7 @@
     Strong<Structure> symbolStructure;
     Strong<Structure> symbolTableStructure;
     Strong<Structure> fixedArrayStructure;
+    Strong<Structure> sourceCodeStructure;
     Strong<Structure> structureChainStructure;
     Strong<Structure> sparseArrayValueMapStructure;
     Strong<Structure> templateRegistryKeyStructure;

Modified: trunk/Source/WebCore/ChangeLog (210572 => 210573)


--- trunk/Source/WebCore/ChangeLog	2017-01-11 01:54:25 UTC (rev 210572)
+++ trunk/Source/WebCore/ChangeLog	2017-01-11 02:26:47 UTC (rev 210573)
@@ -1,3 +1,20 @@
+2017-01-10  Yusuke Suzuki  <[email protected]>
+
+        Implement JSSourceCode to propagate SourceCode in module pipeline
+        https://bugs.webkit.org/show_bug.cgi?id=166861
+
+        Reviewed by Saam Barati.
+
+        Now SourceOrigin is correctly propagated through the module pipeline.
+        So the error reported by http/tests/security/contentSecurityPolicy/module-eval-blocked-expected.html
+        is updated.
+
+        * ForwardingHeaders/runtime/JSSourceCode.h: Added.
+        * bindings/js/JSDOMPromise.h:
+        (WebCore::DeferredPromise::resolveWithCallback):
+        * bindings/js/ScriptModuleLoader.cpp:
+        (WebCore::ScriptModuleLoader::notifyFinished):
+
 2017-01-10  Brent Fulgham  <[email protected]>
 
         File scheme should not allow access of a resource on a different volume.

Added: trunk/Source/WebCore/ForwardingHeaders/runtime/JSSourceCode.h (0 => 210573)


--- trunk/Source/WebCore/ForwardingHeaders/runtime/JSSourceCode.h	                        (rev 0)
+++ trunk/Source/WebCore/ForwardingHeaders/runtime/JSSourceCode.h	2017-01-11 02:26:47 UTC (rev 210573)
@@ -0,0 +1,27 @@
+/*
+ * Copyright (C) 2016 Yusuke Suzuki <[email protected]>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+#include <_javascript_Core/JSSourceCode.h>

Modified: trunk/Source/WebCore/bindings/js/JSDOMPromise.h (210572 => 210573)


--- trunk/Source/WebCore/bindings/js/JSDOMPromise.h	2017-01-11 01:54:25 UTC (rev 210572)
+++ trunk/Source/WebCore/bindings/js/JSDOMPromise.h	2017-01-11 02:26:47 UTC (rev 210573)
@@ -94,6 +94,18 @@
     void reject(ExceptionCode, const String& = { });
     void reject(const JSC::PrivateName&);
 
+    template<typename Callback, typename Value>
+    void resolveWithCallback(Callback callback, Value value)
+    {
+        if (isSuspended())
+            return;
+        ASSERT(m_deferred);
+        ASSERT(m_globalObject);
+        JSC::ExecState* exec = m_globalObject->globalExec();
+        JSC::JSLockHolder locker(exec);
+        resolve(*exec, callback(*exec, *m_globalObject.get(), std::forward<Value>(value)));
+    }
+
     JSC::JSValue promise() const;
 
     bool isSuspended() { return !m_deferred || !canInvokeCallback(); } // The wrapper world has gone away or active DOM objects have been suspended.

Modified: trunk/Source/WebCore/bindings/js/ScriptModuleLoader.cpp (210572 => 210573)


--- trunk/Source/WebCore/bindings/js/ScriptModuleLoader.cpp	2017-01-11 01:54:25 UTC (rev 210572)
+++ trunk/Source/WebCore/bindings/js/ScriptModuleLoader.cpp	2017-01-11 02:26:47 UTC (rev 210573)
@@ -40,6 +40,7 @@
 #include <runtime/JSInternalPromise.h>
 #include <runtime/JSInternalPromiseDeferred.h>
 #include <runtime/JSModuleRecord.h>
+#include <runtime/JSSourceCode.h>
 #include <runtime/JSString.h>
 #include <runtime/Symbol.h>
 
@@ -245,8 +246,10 @@
     }
 
     m_requestURLToResponseURLMap.add(cachedScript.url(), cachedScript.response().url());
-    // FIXME: Let's wrap around ScriptSourceCode to propagate it directly through the module pipeline.
-    promise->resolve<IDLDOMString>(ScriptSourceCode(&cachedScript, JSC::SourceProviderSourceType::Module).source().toString());
+    ScriptSourceCode scriptSourceCode(&cachedScript, JSC::SourceProviderSourceType::Module);
+    promise->resolveWithCallback([] (JSC::ExecState& state, JSDOMGlobalObject&, JSC::SourceCode sourceCode) {
+        return JSC::JSSourceCode::create(state.vm(), WTFMove(sourceCode));
+    }, scriptSourceCode.jsSourceCode());
 }
 
 }
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to