Changeset 210537 in webkit


Ignore:
Timestamp:
Jan 9, 2017 9:58:19 PM (7 years ago)
Author:
Yusuke Suzuki
Message:

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

Reviewed by Saam Barati.

Source/JavaScriptCore:

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.

  • CMakeLists.txt:
  • JavaScriptCore.xcodeproj/project.pbxproj:
  • builtins/ModuleLoaderPrototype.js:

(fulfillFetch):
(requestFetch):

  • jsc.cpp:

(GlobalObject::moduleLoaderFetch):

  • 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:
Location:
trunk
Files:
3 added
19 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r210536 r210537  
     12017-01-09  Yusuke Suzuki  <utatane.tea@gmail.com>
     2
     3        Implement JSSourceCode to propagate SourceCode in module pipeline
     4        https://bugs.webkit.org/show_bug.cgi?id=166861
     5
     6        Reviewed by Saam Barati.
     7
     8        * http/tests/security/contentSecurityPolicy/module-eval-blocked-expected.txt:
     9
    1102017-01-09  Chris Dumez  <cdumez@apple.com>
    211
  • trunk/LayoutTests/http/tests/security/contentSecurityPolicy/module-eval-blocked-expected.txt

    r208788 r210537  
    1 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'".
     1CONSOLE 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'".
    22
    3 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'".
     3CONSOLE 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'".
    44
    5 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'".
     5CONSOLE 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'".
    66
    7 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'".
     7CONSOLE 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'".
    88
    9 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'".
     9CONSOLE 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'".
    1010
    11 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'".
     11CONSOLE 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'".
    1212
    13 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'".
     13CONSOLE 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'".
    1414
    15 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'".
     15CONSOLE 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'".
    1616
    17 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'".
     17CONSOLE 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'".
    1818
    19 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'".
     19CONSOLE 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'".
    2020
    21 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'".
     21CONSOLE 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'".
    2222
    23 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'".
     23CONSOLE 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'".
    2424
    25 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'".
     25CONSOLE 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'".
    2626
    27 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'".
     27CONSOLE 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'".
    2828
    29 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'".
     29CONSOLE 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'".
    3030
    31 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'".
     31CONSOLE 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'".
    3232
    33 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'".
     33CONSOLE 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'".
    3434
    35 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'".
     35CONSOLE 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'".
    3636
    3737
  • trunk/Source/JavaScriptCore/CMakeLists.txt

    r210521 r210537  
    789789    runtime/JSSet.cpp
    790790    runtime/JSSetIterator.cpp
     791    runtime/JSSourceCode.cpp
    791792    runtime/JSString.cpp
    792793    runtime/JSStringIterator.cpp
  • trunk/Source/JavaScriptCore/ChangeLog

    r210535 r210537  
     12017-01-09  Yusuke Suzuki  <utatane.tea@gmail.com>
     2
     3        Implement JSSourceCode to propagate SourceCode in module pipeline
     4        https://bugs.webkit.org/show_bug.cgi?id=166861
     5
     6        Reviewed by Saam Barati.
     7
     8        Instead of propagating source code string, we propagate JSSourceCode
     9        cell in the module pipeline. This allows us to attach a metadata
     10        to the propagated source code string. In particular, it propagates
     11        SourceOrigin through the module pipeline.
     12
     13        * CMakeLists.txt:
     14        * JavaScriptCore.xcodeproj/project.pbxproj:
     15        * builtins/ModuleLoaderPrototype.js:
     16        (fulfillFetch):
     17        (requestFetch):
     18        * jsc.cpp:
     19        (GlobalObject::moduleLoaderFetch):
     20        * llint/LLIntData.cpp:
     21        (JSC::LLInt::Data::performAssertions):
     22        * llint/LowLevelInterpreter.asm:
     23        * runtime/Completion.cpp:
     24        (JSC::loadAndEvaluateModule):
     25        (JSC::loadModule):
     26        * runtime/JSModuleLoader.cpp:
     27        (JSC::JSModuleLoader::provide):
     28        * runtime/JSModuleLoader.h:
     29        * runtime/JSSourceCode.cpp: Added.
     30        (JSC::JSSourceCode::destroy):
     31        * runtime/JSSourceCode.h: Added.
     32        (JSC::JSSourceCode::createStructure):
     33        (JSC::JSSourceCode::create):
     34        (JSC::JSSourceCode::sourceCode):
     35        (JSC::JSSourceCode::JSSourceCode):
     36        * runtime/JSType.h:
     37        * runtime/ModuleLoaderPrototype.cpp:
     38        (JSC::moduleLoaderPrototypeParseModule):
     39        * runtime/VM.cpp:
     40        (JSC::VM::VM):
     41        * runtime/VM.h:
     42
    1432017-01-09  Yusuke Suzuki  <utatane.tea@gmail.com>
    244
  • trunk/Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj

    r210521 r210537  
    23732373                FEF040511AAE662D00BD28B0 /* CompareAndSwapTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FEF040501AAE662D00BD28B0 /* CompareAndSwapTest.cpp */; };
    23742374                FEFD6FC61D5E7992008F2F0B /* JSStringInlines.h in Headers */ = {isa = PBXBuildFile; fileRef = FEFD6FC51D5E7970008F2F0B /* JSStringInlines.h */; settings = {ATTRIBUTES = (Private, ); }; };
     2375                FA3AB211C8494524AB390267 /* JSSourceCode.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F73926918DC64330AFCDF0D7 /* JSSourceCode.cpp */; };
     2376                BDFCB2BBE90F41349E1B0BED /* JSSourceCode.h in Headers */ = {isa = PBXBuildFile; fileRef = 3032175DF1AD47D8998B34E1 /* JSSourceCode.h */; settings = {ATTRIBUTES = (Private, ); }; };
    23752377/* End PBXBuildFile section */
    23762378
     
    49014903                FEF040521AAEC4ED00BD28B0 /* CompareAndSwapTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CompareAndSwapTest.h; path = API/tests/CompareAndSwapTest.h; sourceTree = "<group>"; };
    49024904                FEFD6FC51D5E7970008F2F0B /* JSStringInlines.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSStringInlines.h; sourceTree = "<group>"; };
     4905                F73926918DC64330AFCDF0D7 /* JSSourceCode.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = JSSourceCode.cpp; path = JSSourceCode.cpp; sourceTree = "<group>"; };
     4906                3032175DF1AD47D8998B34E1 /* JSSourceCode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = JSSourceCode.h; path = JSSourceCode.h; sourceTree = "<group>"; };
    49034907/* End PBXFileReference section */
    49044908
     
    67416745                                C2B6D75218A33793004A9301 /* WriteBarrierInlines.h */,
    67426746                                425BA1337E4344E1B269A671 /* SourceOrigin.h */,
     6747                                F73926918DC64330AFCDF0D7 /* JSSourceCode.cpp */,
     6748                                3032175DF1AD47D8998B34E1 /* JSSourceCode.h */,
    67436749                        );
    67446750                        path = runtime;
     
    91159121                                86704B4312DB8A8100A9FE7B /* YarrSyntaxChecker.h in Headers */,
    91169122                                2D342F36F7244096804ADB24 /* SourceOrigin.h in Headers */,
     9123                                BDFCB2BBE90F41349E1B0BED /* JSSourceCode.h in Headers */,
    91179124                        );
    91189125                        runOnlyForDeploymentPostprocessing = 0;
     
    1050310510                                86704B8912DBA33700A9FE7B /* YarrPattern.cpp in Sources */,
    1050410511                                86704B4212DB8A8100A9FE7B /* YarrSyntaxChecker.cpp in Sources */,
     10512                                FA3AB211C8494524AB390267 /* JSSourceCode.cpp in Sources */,
    1050510513                        );
    1050610514                        runOnlyForDeploymentPostprocessing = 0;
  • trunk/Source/JavaScriptCore/builtins/ModuleLoaderPrototype.js

    r210522 r210537  
    128128}
    129129
    130 function fulfillFetch(entry, payload)
     130function fulfillFetch(entry, source)
    131131{
    132132    // https://whatwg.github.io/loader/#fulfill-fetch
     
    136136    if (!entry.fetch)
    137137        entry.fetch = @newPromiseCapability(@InternalPromise).@promise;
    138     this.forceFulfillPromise(entry.fetch, payload);
     138    this.forceFulfillPromise(entry.fetch, source);
    139139    @setStateToMax(entry, @ModuleInstantiate);
    140140}
     
    221221    //     For example, JavaScriptCore shell can provide the hook fetching the resource
    222222    //     from the local file system.
    223     var fetchPromise = this.fetch(key, initiator).then((payload) => {
     223    var fetchPromise = this.fetch(key, initiator).then((source) => {
    224224        @setStateToMax(entry, @ModuleInstantiate);
    225         return payload;
     225        return source;
    226226    });
    227227    entry.fetch = fetchPromise;
  • trunk/Source/JavaScriptCore/jsc.cpp

    r210522 r210537  
    5454#include "JSONObject.h"
    5555#include "JSProxy.h"
     56#include "JSSourceCode.h"
    5657#include "JSString.h"
    5758#include "JSTypedArrays.h"
     
    15771578        return deferred->reject(exec, createError(exec, makeString("Could not open file '", moduleKey, "'.")));
    15781579
    1579     return deferred->resolve(exec, jsString(exec, stringFromUTF(utf8)));
     1580    return deferred->resolve(exec, JSSourceCode::create(exec->vm(), makeSource(stringFromUTF(utf8), SourceOrigin { moduleKey })));
    15801581}
    15811582
  • trunk/Source/JavaScriptCore/llint/LLIntData.cpp

    r210232 r210537  
    157157    STATIC_ASSERT(StringType == 6);
    158158    STATIC_ASSERT(SymbolType == 7);
    159     STATIC_ASSERT(ObjectType == 21);
    160     STATIC_ASSERT(FinalObjectType == 22);
    161     STATIC_ASSERT(JSFunctionType == 24);
    162     STATIC_ASSERT(ArrayType == 32);
    163     STATIC_ASSERT(DerivedArrayType == 33);
    164     STATIC_ASSERT(ProxyObjectType == 51);
    165     STATIC_ASSERT(Int8ArrayType == 34);
    166     STATIC_ASSERT(Int16ArrayType == 35);
    167     STATIC_ASSERT(Int32ArrayType == 36);
    168     STATIC_ASSERT(Uint8ArrayType == 37);
    169     STATIC_ASSERT(Uint8ClampedArrayType == 38);
    170     STATIC_ASSERT(Uint16ArrayType == 39);
    171     STATIC_ASSERT(Uint32ArrayType == 40);
    172     STATIC_ASSERT(Float32ArrayType == 41);
    173     STATIC_ASSERT(Float64ArrayType == 42);
     159    STATIC_ASSERT(ObjectType == 22);
     160    STATIC_ASSERT(FinalObjectType == 23);
     161    STATIC_ASSERT(JSFunctionType == 25);
     162    STATIC_ASSERT(ArrayType == 33);
     163    STATIC_ASSERT(DerivedArrayType == 34);
     164    STATIC_ASSERT(ProxyObjectType == 52);
     165    STATIC_ASSERT(Int8ArrayType == 35);
     166    STATIC_ASSERT(Int16ArrayType == 36);
     167    STATIC_ASSERT(Int32ArrayType == 37);
     168    STATIC_ASSERT(Uint8ArrayType == 38);
     169    STATIC_ASSERT(Uint8ClampedArrayType == 39);
     170    STATIC_ASSERT(Uint16ArrayType == 40);
     171    STATIC_ASSERT(Uint32ArrayType == 41);
     172    STATIC_ASSERT(Float32ArrayType == 42);
     173    STATIC_ASSERT(Float64ArrayType == 43);
    174174    STATIC_ASSERT(MasqueradesAsUndefined == 1);
    175175    STATIC_ASSERT(ImplementsDefaultHasInstance == 2);
  • trunk/Source/JavaScriptCore/llint/LowLevelInterpreter.asm

    r210232 r210537  
    346346const StringType = 6
    347347const SymbolType = 7
    348 const ObjectType = 21
    349 const FinalObjectType = 22
    350 const JSFunctionType = 24
    351 const ArrayType = 32
    352 const DerivedArrayType = 33
    353 const ProxyObjectType = 51
     348const ObjectType = 22
     349const FinalObjectType = 23
     350const JSFunctionType = 25
     351const ArrayType = 33
     352const DerivedArrayType = 34
     353const ProxyObjectType = 52
    354354
    355355# The typed array types need to be numbered in a particular order because of the manually written
    356356# switch statement in get_by_val and put_by_val.
    357 const Int8ArrayType = 34
    358 const Int16ArrayType = 35
    359 const Int32ArrayType = 36
    360 const Uint8ArrayType = 37
    361 const Uint8ClampedArrayType = 38
    362 const Uint16ArrayType = 39
    363 const Uint32ArrayType = 40
    364 const Float32ArrayType = 41
    365 const Float64ArrayType = 42
     357const Int8ArrayType = 35
     358const Int16ArrayType = 36
     359const Int32ArrayType = 37
     360const Uint8ArrayType = 38
     361const Uint8ClampedArrayType = 39
     362const Uint16ArrayType = 40
     363const Uint32ArrayType = 41
     364const Float32ArrayType = 42
     365const Float64ArrayType = 43
    366366
    367367const FirstArrayType = Int8ArrayType
  • trunk/Source/JavaScriptCore/runtime/Completion.cpp

    r208074 r210537  
    194194
    195195    // Insert the given source code to the ModuleLoader registry as the fetched registry entry.
    196     globalObject->moduleLoader()->provide(exec, key, JSModuleLoader::Status::Fetch, source.view().toString());
     196    globalObject->moduleLoader()->provide(exec, key, JSModuleLoader::Status::Fetch, source);
    197197    RETURN_IF_EXCEPTION(scope, rejectPromise(exec, globalObject));
    198198
     
    233233    // Insert the given source code to the ModuleLoader registry as the fetched registry entry.
    234234    // FIXME: Introduce JSSourceCode object to wrap around this source.
    235     globalObject->moduleLoader()->provide(exec, key, JSModuleLoader::Status::Fetch, source.view().toString());
     235    globalObject->moduleLoader()->provide(exec, key, JSModuleLoader::Status::Fetch, source);
    236236    RETURN_IF_EXCEPTION(scope, rejectPromise(exec, globalObject));
    237237
  • trunk/Source/JavaScriptCore/runtime/JSModuleLoader.cpp

    r210522 r210537  
    3939#include "JSModuleEnvironment.h"
    4040#include "JSModuleRecord.h"
     41#include "JSSourceCode.h"
    4142#include "ModuleAnalyzer.h"
    4243#include "ModuleLoaderPrototype.h"
     
    7677}
    7778
    78 JSValue JSModuleLoader::provide(ExecState* exec, JSValue key, Status status, const String& source)
    79 {
     79JSValue JSModuleLoader::provide(ExecState* exec, JSValue key, Status status, const SourceCode& sourceCode)
     80{
     81    VM& vm = exec->vm();
    8082    JSObject* function = jsCast<JSObject*>(get(exec, exec->propertyNames().builtinNames().providePublicName()));
    8183    CallData callData;
     
    8385    ASSERT(callType != CallType::None);
    8486
     87    SourceCode source { sourceCode };
    8588    MarkedArgumentBuffer arguments;
    8689    arguments.append(key);
    8790    arguments.append(jsNumber(status));
    88     arguments.append(jsString(exec, source));
     91    arguments.append(JSSourceCode::create(vm, WTFMove(source)));
    8992
    9093    return call(exec, function, callType, callData, this, arguments);
  • trunk/Source/JavaScriptCore/runtime/JSModuleLoader.h

    r210522 r210537  
    3333class JSInternalPromise;
    3434class JSModuleNamespaceObject;
     35class SourceCode;
    3536
    3637class JSModuleLoader : public JSNonFinalObject {
     
    6364
    6465    // APIs to control the module loader.
    65     JSValue provide(ExecState*, JSValue key, Status, const String&);
     66    JSValue provide(ExecState*, JSValue key, Status, const SourceCode&);
    6667    JSInternalPromise* loadAndEvaluateModule(ExecState*, JSValue moduleName, JSValue referrer, JSValue initiator);
    6768    JSInternalPromise* loadModule(ExecState*, JSValue moduleName, JSValue referrer, JSValue initiator);
  • trunk/Source/JavaScriptCore/runtime/JSType.h

    r210229 r210537  
    5151
    5252    JSFixedArrayType,
     53    JSSourceCodeType,
    5354
    5455    // The ObjectType value must come before any JSType that is a subclass of JSObject.
  • trunk/Source/JavaScriptCore/runtime/ModuleLoaderPrototype.cpp

    r210522 r210537  
    4040#include "JSModuleNamespaceObject.h"
    4141#include "JSModuleRecord.h"
     42#include "JSSourceCode.h"
    4243#include "ModuleAnalyzer.h"
    4344#include "Nodes.h"
     
    113114    RETURN_IF_EXCEPTION(scope, encodedJSValue());
    114115
    115     String source = exec->argument(1).toWTFString(exec);
    116     RETURN_IF_EXCEPTION(scope, encodedJSValue());
    117 
    118     SourceCode sourceCode = makeSource(source, SourceOrigin { moduleKey.impl() }, moduleKey.impl(), TextPosition(), SourceProviderSourceType::Module);
     116    auto* jsSourceCode = jsDynamicCast<JSSourceCode*>(exec->argument(1));
     117    if (!jsSourceCode)
     118        return throwVMTypeError(exec, scope);
     119    SourceCode sourceCode = jsSourceCode->sourceCode();
    119120
    120121    CodeProfiling profile(sourceCode);
  • trunk/Source/JavaScriptCore/runtime/VM.cpp

    r210139 r210537  
    7272#include "JSPromiseDeferred.h"
    7373#include "JSPropertyNameEnumerator.h"
     74#include "JSSourceCode.h"
    7475#include "JSTemplateRegistryKey.h"
    7576#include "JSWebAssembly.h"
     
    239240    symbolTableStructure.set(*this, SymbolTable::createStructure(*this, 0, jsNull()));
    240241    fixedArrayStructure.set(*this, JSFixedArray::createStructure(*this, 0, jsNull()));
     242    sourceCodeStructure.set(*this, JSSourceCode::createStructure(*this, 0, jsNull()));
    241243    structureChainStructure.set(*this, StructureChain::createStructure(*this, 0, jsNull()));
    242244    sparseArrayValueMapStructure.set(*this, SparseArrayValueMap::createStructure(*this, 0, jsNull()));
  • trunk/Source/JavaScriptCore/runtime/VM.h

    r210201 r210537  
    327327    Strong<Structure> symbolTableStructure;
    328328    Strong<Structure> fixedArrayStructure;
     329    Strong<Structure> sourceCodeStructure;
    329330    Strong<Structure> structureChainStructure;
    330331    Strong<Structure> sparseArrayValueMapStructure;
  • trunk/Source/WebCore/ChangeLog

    r210536 r210537  
     12017-01-09  Yusuke Suzuki  <utatane.tea@gmail.com>
     2
     3        Implement JSSourceCode to propagate SourceCode in module pipeline
     4        https://bugs.webkit.org/show_bug.cgi?id=166861
     5
     6        Reviewed by Saam Barati.
     7
     8        Now SourceOrigin is correctly propagated through the module pipeline.
     9        So the error reported by http/tests/security/contentSecurityPolicy/module-eval-blocked-expected.html
     10        is updated.
     11
     12        * ForwardingHeaders/runtime/JSSourceCode.h: Added.
     13        * bindings/js/JSDOMPromise.h:
     14        (WebCore::DeferredPromise::resolveWithCallback):
     15        * bindings/js/ScriptModuleLoader.cpp:
     16        (WebCore::ScriptModuleLoader::notifyFinished):
     17
    1182017-01-09  Chris Dumez  <cdumez@apple.com>
    219
  • trunk/Source/WebCore/bindings/js/JSDOMPromise.h

    r209897 r210537  
    9595    void reject(const JSC::PrivateName&);
    9696
     97    template<typename Callback, typename Value>
     98    void resolveWithCallback(Callback callback, Value value)
     99    {
     100        if (isSuspended())
     101            return;
     102        ASSERT(m_deferred);
     103        ASSERT(m_globalObject);
     104        JSC::ExecState* exec = m_globalObject->globalExec();
     105        JSC::JSLockHolder locker(exec);
     106        resolve(*exec, callback(*exec, *m_globalObject.get(), std::forward<Value>(value)));
     107    }
     108
    97109    JSC::JSValue promise() const;
    98110
  • trunk/Source/WebCore/bindings/js/ScriptModuleLoader.cpp

    r210319 r210537  
    4141#include <runtime/JSInternalPromiseDeferred.h>
    4242#include <runtime/JSModuleRecord.h>
     43#include <runtime/JSSourceCode.h>
    4344#include <runtime/JSString.h>
    4445#include <runtime/Symbol.h>
     
    246247
    247248    m_requestURLToResponseURLMap.add(cachedScript.url(), cachedScript.response().url());
    248     // FIXME: Let's wrap around ScriptSourceCode to propagate it directly through the module pipeline.
    249     promise->resolve<IDLDOMString>(ScriptSourceCode(&cachedScript, JSC::SourceProviderSourceType::Module).source().toString());
    250 }
    251 
    252 }
     249    ScriptSourceCode scriptSourceCode(&cachedScript, JSC::SourceProviderSourceType::Module);
     250    promise->resolveWithCallback([] (JSC::ExecState& state, JSDOMGlobalObject&, JSC::SourceCode sourceCode) {
     251        return JSC::JSSourceCode::create(state.vm(), WTFMove(sourceCode));
     252    }, scriptSourceCode.jsSourceCode());
     253}
     254
     255}
Note: See TracChangeset for help on using the changeset viewer.