Changeset 209171 in webkit
- Timestamp:
- Nov 30, 2016 7:54:24 PM (7 years ago)
- Location:
- trunk/Source/JavaScriptCore
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/ChangeLog
r209162 r209171 1 2016-11-30 Yusuke Suzuki <utatane.tea@gmail.com> 2 3 WebAssembly JS API: export a module namespace object instead of a module environment 4 https://bugs.webkit.org/show_bug.cgi?id=165121 5 6 Reviewed by Saam Barati. 7 8 This patch setup AbstractModuleRecord further for WebAssemblyModuleRecord. 9 For exported entries in a wasm instance, we set up exported entries for 10 AbstractModuleRecord. This allows us to export WASM exported functions in 11 the module handling code. 12 13 Since the exported entries in the abstract module record are correctly 14 instantiated, the module namespace object for WASM module also starts 15 working correctly. So we start exposing the module namespace object 16 as `instance.exports` instead of the module environment object. 17 18 And we move SourceCode, lexicalVariables, and declaredVariables fields to 19 JSModuleRecord since they are related to JS source code (in the spec words, 20 they are related to the source text module record). 21 22 * runtime/AbstractModuleRecord.cpp: 23 (JSC::AbstractModuleRecord::AbstractModuleRecord): 24 * runtime/AbstractModuleRecord.h: 25 (JSC::AbstractModuleRecord::sourceCode): Deleted. 26 (JSC::AbstractModuleRecord::declaredVariables): Deleted. 27 (JSC::AbstractModuleRecord::lexicalVariables): Deleted. 28 * runtime/JSModuleRecord.cpp: 29 (JSC::JSModuleRecord::JSModuleRecord): 30 * runtime/JSModuleRecord.h: 31 (JSC::JSModuleRecord::sourceCode): 32 (JSC::JSModuleRecord::declaredVariables): 33 (JSC::JSModuleRecord::lexicalVariables): 34 * wasm/WasmFormat.cpp: 35 * wasm/js/JSWebAssemblyInstance.cpp: 36 (JSC::JSWebAssemblyInstance::finishCreation): 37 * wasm/js/WebAssemblyFunction.cpp: 38 * wasm/js/WebAssemblyInstanceConstructor.cpp: 39 (JSC::constructJSWebAssemblyInstance): 40 * wasm/js/WebAssemblyModuleRecord.cpp: 41 (JSC::WebAssemblyModuleRecord::create): 42 (JSC::WebAssemblyModuleRecord::WebAssemblyModuleRecord): 43 (JSC::WebAssemblyModuleRecord::finishCreation): 44 WebAssemblyModuleRecord::link should perform linking things. 45 So allocating exported entries should be done here. 46 (JSC::WebAssemblyModuleRecord::link): 47 * wasm/js/WebAssemblyModuleRecord.h: 48 1 49 2016-11-30 Mark Lam <mark.lam@apple.com> 2 50 -
trunk/Source/JavaScriptCore/runtime/AbstractModuleRecord.cpp
r209123 r209171 39 39 const ClassInfo AbstractModuleRecord::s_info = { "AbstractModuleRecord", &Base::s_info, 0, CREATE_METHOD_TABLE(AbstractModuleRecord) }; 40 40 41 AbstractModuleRecord::AbstractModuleRecord(VM& vm, Structure* structure, const Identifier& moduleKey , const SourceCode& sourceCode, const VariableEnvironment& declaredVariables, const VariableEnvironment& lexicalVariables)41 AbstractModuleRecord::AbstractModuleRecord(VM& vm, Structure* structure, const Identifier& moduleKey) 42 42 : Base(vm, structure) 43 43 , m_moduleKey(moduleKey) 44 , m_sourceCode(sourceCode)45 , m_declaredVariables(declaredVariables)46 , m_lexicalVariables(lexicalVariables)47 44 { 48 45 } -
trunk/Source/JavaScriptCore/runtime/AbstractModuleRecord.h
r209123 r209171 89 89 std::optional<ExportEntry> tryGetExportEntry(UniquedStringImpl* exportName); 90 90 91 const SourceCode& sourceCode() const { return m_sourceCode; }92 91 const Identifier& moduleKey() const { return m_moduleKey; } 93 92 const OrderedIdentifierSet& requestedModules() const { return m_requestedModules; } … … 95 94 const ImportEntries& importEntries() const { return m_importEntries; } 96 95 const OrderedIdentifierSet& starExportEntries() const { return m_starExportEntries; } 97 98 const VariableEnvironment& declaredVariables() const { return m_declaredVariables; }99 const VariableEnvironment& lexicalVariables() const { return m_lexicalVariables; }100 96 101 97 void dump(); … … 127 123 128 124 protected: 129 AbstractModuleRecord(VM&, Structure*, const Identifier& , const SourceCode&, const VariableEnvironment&, const VariableEnvironment&);125 AbstractModuleRecord(VM&, Structure*, const Identifier&); 130 126 void finishCreation(ExecState*, VM&); 131 127 … … 143 139 // The loader resolves the given module name to the module key. The module key is the unique value to represent this module. 144 140 Identifier m_moduleKey; 145 146 SourceCode m_sourceCode;147 148 VariableEnvironment m_declaredVariables;149 VariableEnvironment m_lexicalVariables;150 141 151 142 // Currently, we don't keep the occurrence order of the import / export entries. -
trunk/Source/JavaScriptCore/runtime/JSModuleRecord.cpp
r209123 r209171 51 51 } 52 52 JSModuleRecord::JSModuleRecord(VM& vm, Structure* structure, const Identifier& moduleKey, const SourceCode& sourceCode, const VariableEnvironment& declaredVariables, const VariableEnvironment& lexicalVariables) 53 : Base(vm, structure, moduleKey, sourceCode, declaredVariables, lexicalVariables) 53 : Base(vm, structure, moduleKey) 54 , m_sourceCode(sourceCode) 55 , m_declaredVariables(declaredVariables) 56 , m_lexicalVariables(lexicalVariables) 54 57 { 55 58 } -
trunk/Source/JavaScriptCore/runtime/JSModuleRecord.h
r209123 r209171 52 52 JS_EXPORT_PRIVATE JSValue evaluate(ExecState*); 53 53 54 const SourceCode& sourceCode() const { return m_sourceCode; } 55 const VariableEnvironment& declaredVariables() const { return m_declaredVariables; } 56 const VariableEnvironment& lexicalVariables() const { return m_lexicalVariables; } 57 54 58 ModuleProgramExecutable* moduleProgramExecutable() const { return m_moduleProgramExecutable.get(); } 55 59 … … 64 68 void instantiateDeclarations(ExecState*, ModuleProgramExecutable*); 65 69 70 SourceCode m_sourceCode; 71 VariableEnvironment m_declaredVariables; 72 VariableEnvironment m_lexicalVariables; 66 73 WriteBarrier<ModuleProgramExecutable> m_moduleProgramExecutable; 67 74 }; -
trunk/Source/JavaScriptCore/wasm/WasmFormat.cpp
r208401 r209171 32 32 #include "WasmMemory.h" 33 33 34 #if COMPILER(GCC) && ASSERT_DISABLED 35 #pragma GCC diagnostic push 36 #pragma GCC diagnostic ignored "-Wreturn-type" 37 #endif // COMPILER(GCC) && ASSERT_DISABLED 38 34 39 namespace JSC { namespace Wasm { 35 40 … … 54 59 } } // namespace JSC::Wasm 55 60 61 #if COMPILER(GCC) && ASSERT_DISABLED 62 #pragma GCC diagnostic pop 63 #endif // COMPILER(GCC) && ASSERT_DISABLED 64 56 65 #endif // ENABLE(WEBASSEMBLY) -
trunk/Source/JavaScriptCore/wasm/js/JSWebAssemblyInstance.cpp
r209123 r209171 57 57 { 58 58 Base::finishCreation(vm); 59 ASSERT(inherits(info())); 59 60 m_module.set(vm, this, module); 60 61 m_moduleNamespaceObject.set(vm, this, moduleNamespaceObject); 61 // FIXME this should put the module namespace object onto the exports object, instead of moduleEnvironment in WebAssemblyInstanceConstructor. https://bugs.webkit.org/show_bug.cgi?id=165121 62 ASSERT(inherits(info())); 62 putDirect(vm, Identifier::fromString(&vm, "exports"), moduleNamespaceObject, None); 63 63 } 64 64 -
trunk/Source/JavaScriptCore/wasm/js/WebAssemblyFunction.cpp
r209123 r209171 34 34 #include "JSObject.h" 35 35 #include "JSWebAssemblyInstance.h" 36 #include "LL intThunks.h"36 #include "LLIntThunks.h" 37 37 #include "ProtoCallFrame.h" 38 38 #include "VM.h" -
trunk/Source/JavaScriptCore/wasm/js/WebAssemblyInstanceConstructor.cpp
r209123 r209171 73 73 74 74 Identifier moduleKey = Identifier::fromUid(PrivateName(PrivateName::Description, "WebAssemblyInstance")); 75 SourceCode sourceCode; 76 VariableEnvironment declaredVariables; 77 VariableEnvironment lexicalVariables; 78 WebAssemblyModuleRecord* moduleRecord = WebAssemblyModuleRecord::create(state, vm, globalObject->webAssemblyModuleRecordStructure(), moduleKey, sourceCode, declaredVariables, lexicalVariables); 75 WebAssemblyModuleRecord* moduleRecord = WebAssemblyModuleRecord::create(state, vm, globalObject->webAssemblyModuleRecordStructure(), moduleKey, moduleInformation); 79 76 RETURN_IF_EXCEPTION(scope, encodedJSValue()); 80 77 … … 89 86 if (verbose) 90 87 moduleRecord->dump(); 91 // FIXME the following should be in JSWebAssemblyInstance instead of here. https://bugs.webkit.org/show_bug.cgi?id=16512192 instance->putDirect(vm, Identifier::fromString(&vm, "exports"), JSValue(moduleRecord->moduleEnvironment()), None);93 88 JSValue startResult = moduleRecord->evaluate(state); 94 89 UNUSED_PARAM(startResult); -
trunk/Source/JavaScriptCore/wasm/js/WebAssemblyModuleRecord.cpp
r209123 r209171 47 47 } 48 48 49 WebAssemblyModuleRecord* WebAssemblyModuleRecord::create(ExecState* exec, VM& vm, Structure* structure, const Identifier& moduleKey, const SourceCode& sourceCode, const VariableEnvironment& declaredVariables, const VariableEnvironment& lexicalVariables)49 WebAssemblyModuleRecord* WebAssemblyModuleRecord::create(ExecState* exec, VM& vm, Structure* structure, const Identifier& moduleKey, const Wasm::ModuleInformation& moduleInformation) 50 50 { 51 WebAssemblyModuleRecord* instance = new (NotNull, allocateCell<WebAssemblyModuleRecord>(vm.heap)) WebAssemblyModuleRecord(vm, structure, moduleKey , sourceCode, declaredVariables, lexicalVariables);52 instance->finishCreation(exec, vm );51 WebAssemblyModuleRecord* instance = new (NotNull, allocateCell<WebAssemblyModuleRecord>(vm.heap)) WebAssemblyModuleRecord(vm, structure, moduleKey); 52 instance->finishCreation(exec, vm, moduleInformation); 53 53 return instance; 54 54 } 55 55 56 WebAssemblyModuleRecord::WebAssemblyModuleRecord(VM& vm, Structure* structure, const Identifier& moduleKey , const SourceCode& sourceCode, const VariableEnvironment& declaredVariables, const VariableEnvironment& lexicalVariables)57 : Base(vm, structure, moduleKey , sourceCode, declaredVariables, lexicalVariables)56 WebAssemblyModuleRecord::WebAssemblyModuleRecord(VM& vm, Structure* structure, const Identifier& moduleKey) 57 : Base(vm, structure, moduleKey) 58 58 { 59 59 } … … 65 65 } 66 66 67 void WebAssemblyModuleRecord::finishCreation(ExecState* exec, VM& vm )67 void WebAssemblyModuleRecord::finishCreation(ExecState* exec, VM& vm, const Wasm::ModuleInformation& moduleInformation) 68 68 { 69 69 Base::finishCreation(exec, vm); 70 70 ASSERT(inherits(info())); 71 for (const auto& exp : moduleInformation.exports) { 72 switch (exp.kind) { 73 case Wasm::External::Function: { 74 addExportEntry(ExportEntry::createLocal(exp.field, exp.field)); 75 break; 76 } 77 case Wasm::External::Table: { 78 // FIXME https://bugs.webkit.org/show_bug.cgi?id=164135 79 break; 80 } 81 case Wasm::External::Memory: { 82 // FIXME https://bugs.webkit.org/show_bug.cgi?id=164134 83 break; 84 } 85 case Wasm::External::Global: { 86 // FIXME https://bugs.webkit.org/show_bug.cgi?id=164133 87 // In the MVP, only immutable global variables can be exported. 88 break; 89 } 90 } 91 } 71 92 } 72 93 … … 93 114 // Let exports be a list of (string, JS value) pairs that is mapped from each external value e in instance.exports as follows: 94 115 JSModuleEnvironment* moduleEnvironment = JSModuleEnvironment::create(vm, globalObject, nullptr, exportSymbolTable, JSValue(), this); 95 unsigned offset = 0;96 116 for (const auto& exp : moduleInformation.exports) { 97 117 JSValue exportedValue; 98 PutPropertySlot slot(this);99 slot.setNewProperty(this, offset++);100 118 switch (exp.kind) { 101 119 case Wasm::External::Function: { -
trunk/Source/JavaScriptCore/wasm/js/WebAssemblyModuleRecord.h
r209123 r209171 29 29 30 30 #include "AbstractModuleRecord.h" 31 #include "WasmFormat.h" 31 32 32 33 namespace JSC { … … 44 45 45 46 static Structure* createStructure(VM&, JSGlobalObject*, JSValue); 46 static WebAssemblyModuleRecord* create(ExecState*, VM&, Structure*, const Identifier&, const SourceCode&, const VariableEnvironment&, const VariableEnvironment&);47 static WebAssemblyModuleRecord* create(ExecState*, VM&, Structure*, const Identifier&, const Wasm::ModuleInformation&); 47 48 48 49 void link(ExecState*, JSWebAssemblyInstance*); … … 50 51 51 52 private: 52 WebAssemblyModuleRecord(VM&, Structure*, const Identifier& , const SourceCode&, const VariableEnvironment&, const VariableEnvironment&);53 WebAssemblyModuleRecord(VM&, Structure*, const Identifier&); 53 54 54 void finishCreation(ExecState*, VM& );55 void finishCreation(ExecState*, VM&, const Wasm::ModuleInformation&); 55 56 static void destroy(JSCell*); 56 57
Note: See TracChangeset
for help on using the changeset viewer.