Changeset 209630 in webkit
- Timestamp:
- Dec 9, 2016, 2:38:39 PM (9 years ago)
- Location:
- trunk
- Files:
-
- 5 added
- 1 deleted
- 34 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JSTests/ChangeLog
r209597 r209630 1 2016-12-09 Saam Barati <[email protected]> 2 3 WebAssembly JS API: implement importing and defining Memory 4 https://bugs.webkit.org/show_bug.cgi?id=164134 5 6 Reviewed by Keith Miller. 7 8 * wasm/Builder.js: 9 (const._importMemoryContinuation.section): 10 (const._importMemoryContinuation.assert): 11 (const._importMemoryContinuation): 12 (const._exportFunctionContinuation.const): Deleted. 13 (const._exportFunctionContinuation): Deleted. 14 * wasm/Builder_WebAssemblyBinary.js: 15 (const.emitters.Import): 16 * wasm/js-api/test_basic_api.js: 17 (const.c.in.constructorProperties.switch): 18 * wasm/js-api/test_memory.js: Added. 19 (assert): 20 (binaryShouldNotParse): 21 (test): 22 (test.testMemImportError): 23 * wasm/js-api/test_memory_constructor.js: Added. 24 (assert): 25 (throw.new.Error): 26 (testInvalidSize): 27 (assert.testInvalidInitial): 28 (testInvalidInitial.testInvalidMaximum): 29 (testInvalidInitial): 30 (testInvalidMaximum): 31 * wasm/self-test/test_BuilderJSON.js: 32 1 33 2016-12-08 JF Bastien <[email protected]> 2 34 -
trunk/JSTests/wasm/Builder.js
r209306 r209630 103 103 }; 104 104 105 const _importMemoryContinuation = (builder, section, nextBuilder) => { 106 return (module, field, memoryDescription) => { 107 assert.isString(module, `Import function module should be a string, got "${module}"`); 108 assert.isString(field, `Import function field should be a string, got "${field}"`); 109 section.data.push({module, field, kind: "Memory", memoryDescription}); 110 return nextBuilder; 111 }; 112 }; 113 105 114 const _exportFunctionContinuation = (builder, section, nextBuilder) => { 106 115 return (field, index, type) => { … … 111 120 type = _maybeRegisterType(builder, type); 112 121 } 122 113 123 // We can't check much about "index" here because the Code section succeeds the Export section. More work is done at Code().End() time. 114 124 switch (typeof(index)) { … … 126 136 default: throw new Error(`Export section's index must be a string or a number, got ${index}`); 127 137 } 138 128 139 const correspondingImport = builder._getFunctionFromIndexSpace(index); 129 140 const importSection = builder._getSection("Import"); … … 369 380 End: () => this, 370 381 Table: () => { throw new Error(`Unimplemented: import table`); }, 371 Memory: () => { throw new Error(`Unimplemented: import memory`); },372 382 Global: () => { throw new Error(`Unimplemented: import global`); }, 373 383 }; 374 384 importBuilder.Function = _importFunctionContinuation(this, s, importBuilder); 385 importBuilder.Memory = _importMemoryContinuation(this, s, importBuilder); 375 386 return importBuilder; 376 387 }; … … 466 477 if (typeof(e.type) === "undefined") { 467 478 // This must be a function export from the Code section (re-exports were handled earlier). 468 const functionIndexSpaceOffset = importSection ? importSection.data.length : 0; 479 let functionIndexSpaceOffset = 0; 480 if (importSection) { 481 for (const {kind} of importSection.data) { 482 if (kind === "Function") 483 ++functionIndexSpaceOffset; 484 } 485 } 469 486 const functionIndex = e.index - functionIndexSpaceOffset; 470 487 e.type = codeSection.data[functionIndex].type; -
trunk/JSTests/wasm/Builder_WebAssemblyBinary.js
r209306 r209630 54 54 switch (entry.kind) { 55 55 default: throw new Error(`Implementation problem: unexpected kind ${entry.kind}`); 56 case "Function": put(bin, "varuint32", entry.type); break; 56 case "Function": { 57 put(bin, "varuint32", entry.type); 58 break; 59 } 57 60 case "Table": throw new Error(`Not yet implemented`); 58 case "Memory": throw new Error(`Not yet implemented`); 61 case "Memory": { 62 let {initial, maximum} = entry.memoryDescription; 63 assert.truthy(typeof initial === "number", "We expect 'initial' to be a number"); 64 initial |= 0; 65 let hasMaximum = 0; 66 if (typeof maximum === "number") { 67 maximum |= 0; 68 hasMaximum = 1; 69 } else { 70 assert.truthy(typeof maximum === "undefined", "We expect 'maximum' to be a number if it's defined"); 71 } 72 73 put(bin, "varuint1", hasMaximum); 74 put(bin, "varuint32", initial); 75 if (hasMaximum) 76 put(bin, "varuint32", maximum); 77 break; 78 }; 59 79 case "Global": throw new Error(`Not yet implemented`); 60 80 } -
trunk/JSTests/wasm/js-api/test_basic_api.js
r209306 r209630 76 76 break; 77 77 case "Memory": 78 // FIXME Implement and test these APIs further. For now they just throw. https://bugs.webkit.org/show_bug.cgi?id=159775 79 assert.throws(() => new WebAssembly[c](), Error, `WebAssembly doesn't yet implement the ${c} constructor property`); 78 new WebAssembly.Memory({initial: 20}); 80 79 break; 81 80 case "Table": -
trunk/JSTests/wasm/self-test/test_BuilderJSON.js
r209165 r209630 570 570 })(); 571 571 572 (function MemoryImport() { 573 const builder = (new Builder()) 574 .Type().End() 575 .Import() 576 .Memory("__module__", "__field__", {initial: 30, maximum: 31}) 577 .End() 578 .Code().End(); 579 580 const json = JSON.parse(builder.json()); 581 assert.eq(json.section.length, 3); 582 assert.eq(json.section[1].name, "Import"); 583 assert.eq(json.section[1].data.length, 1); 584 assert.eq(json.section[1].data[0].module, "__module__"); 585 assert.eq(json.section[1].data[0].field, "__field__"); 586 assert.eq(json.section[1].data[0].kind, "Memory"); 587 assert.eq(json.section[1].data[0].memoryDescription.initial, 30); 588 assert.eq(json.section[1].data[0].memoryDescription.maximum, 31); 589 })(); 590 572 591 // FIXME test type mismatch with select. https://bugs.webkit.org/show_bug.cgi?id=163267 -
trunk/Source/JavaScriptCore/CMakeLists.txt
r209570 r209630 903 903 wasm/WasmFormat.cpp 904 904 wasm/WasmMemory.cpp 905 wasm/WasmMemoryInformation.cpp 905 906 wasm/WasmModuleParser.cpp 906 907 wasm/WasmPlan.cpp -
trunk/Source/JavaScriptCore/ChangeLog
r209629 r209630 1 2016-12-09 Saam Barati <[email protected]> 2 3 WebAssembly JS API: implement importing and defining Memory 4 https://bugs.webkit.org/show_bug.cgi?id=164134 5 6 Reviewed by Keith Miller. 7 8 This patch implements the WebAssembly.Memory object. It refactors 9 the code to now associate a Memory with the instance instead of 10 the Module. 11 12 * CMakeLists.txt: 13 * JavaScriptCore.xcodeproj/project.pbxproj: 14 * jsc.cpp: 15 (functionTestWasmModuleFunctions): 16 * runtime/VM.h: 17 * shell/CMakeLists.txt: 18 * testWasm.cpp: Removed. 19 This has bitrotted. I'm removing it. 20 21 * wasm/WasmB3IRGenerator.cpp: 22 (JSC::Wasm::B3IRGenerator::B3IRGenerator): 23 (JSC::Wasm::sizeOfLoadOp): 24 (JSC::Wasm::createJSToWasmWrapper): 25 (JSC::Wasm::parseAndCompile): 26 * wasm/WasmB3IRGenerator.h: 27 * wasm/WasmFormat.cpp: 28 (JSC::Wasm::ModuleInformation::~ModuleInformation): Deleted. 29 * wasm/WasmFormat.h: 30 * wasm/WasmMemory.cpp: 31 (JSC::Wasm::Memory::Memory): 32 * wasm/WasmMemory.h: 33 (JSC::Wasm::Memory::size): 34 (JSC::Wasm::Memory::initial): 35 (JSC::Wasm::Memory::maximum): 36 (JSC::Wasm::Memory::pinnedRegisters): Deleted. 37 * wasm/WasmMemoryInformation.cpp: Added. 38 (JSC::Wasm::MemoryInformation::MemoryInformation): 39 * wasm/WasmMemoryInformation.h: Added. 40 (JSC::Wasm::MemoryInformation::MemoryInformation): 41 (JSC::Wasm::MemoryInformation::pinnedRegisters): 42 (JSC::Wasm::MemoryInformation::initial): 43 (JSC::Wasm::MemoryInformation::maximum): 44 (JSC::Wasm::MemoryInformation::isImport): 45 (JSC::Wasm::MemoryInformation::operator bool): 46 * wasm/WasmModuleParser.cpp: 47 (JSC::Wasm::ModuleParser::parseImport): 48 (JSC::Wasm::ModuleParser::parseMemoryHelper): 49 (JSC::Wasm::ModuleParser::parseMemory): 50 (JSC::Wasm::ModuleParser::parseExport): 51 * wasm/WasmModuleParser.h: 52 * wasm/WasmPageCount.h: Added. Implement a new way of describing Wasm 53 pages and then asking for how many bytes a quantity of pages is. This 54 class also makes it clear when we're talking about bytes or pages. 55 56 (JSC::Wasm::PageCount::PageCount): 57 (JSC::Wasm::PageCount::bytes): 58 (JSC::Wasm::PageCount::isValid): 59 (JSC::Wasm::PageCount::max): 60 (JSC::Wasm::PageCount::operator bool): 61 (JSC::Wasm::PageCount::operator<): 62 (JSC::Wasm::PageCount::operator>): 63 (JSC::Wasm::PageCount::operator>=): 64 * wasm/WasmPlan.cpp: 65 (JSC::Wasm::Plan::run): 66 * wasm/WasmPlan.h: 67 (JSC::Wasm::Plan::memory): Deleted. 68 * wasm/WasmValidate.cpp: 69 (JSC::Wasm::Validate::hasMemory): 70 (JSC::Wasm::Validate::Validate): 71 (JSC::Wasm::validateFunction): 72 * wasm/WasmValidate.h: 73 * wasm/generateWasmValidateInlinesHeader.py: 74 * wasm/js/JSWebAssemblyInstance.cpp: 75 (JSC::JSWebAssemblyInstance::visitChildren): 76 * wasm/js/JSWebAssemblyInstance.h: 77 (JSC::JSWebAssemblyInstance::memory): 78 (JSC::JSWebAssemblyInstance::setMemory): 79 (JSC::JSWebAssemblyInstance::offsetOfImportFunctions): 80 (JSC::JSWebAssemblyInstance::allocationSize): 81 * wasm/js/JSWebAssemblyMemory.cpp: 82 (JSC::JSWebAssemblyMemory::create): 83 (JSC::JSWebAssemblyMemory::JSWebAssemblyMemory): 84 (JSC::JSWebAssemblyMemory::buffer): 85 (JSC::JSWebAssemblyMemory::visitChildren): 86 * wasm/js/JSWebAssemblyMemory.h: 87 (JSC::JSWebAssemblyMemory::memory): 88 * wasm/js/WebAssemblyFunction.cpp: 89 (JSC::callWebAssemblyFunction): 90 * wasm/js/WebAssemblyInstanceConstructor.cpp: 91 Handle importing and creating of memory according 92 to the spec. This also does the needed validation 93 of making sure the memory defined in the module 94 is compatible with the imported memory. 95 96 (JSC::constructJSWebAssemblyInstance): 97 * wasm/js/WebAssemblyMemoryConstructor.cpp: 98 (JSC::constructJSWebAssemblyMemory): 99 (JSC::callJSWebAssemblyMemory): 100 * wasm/js/WebAssemblyMemoryPrototype.cpp: 101 (JSC::webAssemblyMemoryProtoFuncBuffer): 102 (JSC::WebAssemblyMemoryPrototype::create): 103 (JSC::WebAssemblyMemoryPrototype::finishCreation): 104 * wasm/js/WebAssemblyMemoryPrototype.h: 105 * wasm/js/WebAssemblyModuleRecord.cpp: 106 (JSC::WebAssemblyModuleRecord::finishCreation): 107 (JSC::WebAssemblyModuleRecord::link): 108 1 109 2016-12-09 Joseph Pecoraro <[email protected]> 2 110 -
trunk/Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj
r209570 r209630 26 26 ); 27 27 dependencies = ( 28 539EB0831D5560F400C82EF7 /* PBXTargetDependency */,29 28 0F6183471C45F67A0072450B /* PBXTargetDependency */, 30 29 0F93275D1C20BF3A00CF6564 /* PBXTargetDependency */, … … 1288 1287 5370B4F61BF26205005C40FC /* AdaptiveInferredPropertyValueWatchpointBase.h in Headers */ = {isa = PBXBuildFile; fileRef = 5370B4F41BF25EA2005C40FC /* AdaptiveInferredPropertyValueWatchpointBase.h */; }; 1289 1288 53917E7B1B7906FA000EBD33 /* JSGenericTypedArrayViewPrototypeFunctions.h in Headers */ = {isa = PBXBuildFile; fileRef = 53917E7A1B7906E4000EBD33 /* JSGenericTypedArrayViewPrototypeFunctions.h */; }; 1290 539EB0791D55607000C82EF7 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 51F0EB6105C86C6B00E6DF1B /* Foundation.framework */; };1291 539EB07A1D55607000C82EF7 /* JavaScriptCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 932F5BD90822A1C700736975 /* JavaScriptCore.framework */; };1292 539EB0811D55608A00C82EF7 /* testWasm.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 539EB0711D553DF800C82EF7 /* testWasm.cpp */; };1293 1289 539FB8BA1C99DA7C00940FA1 /* JSArrayInlines.h in Headers */ = {isa = PBXBuildFile; fileRef = 539FB8B91C99DA7C00940FA1 /* JSArrayInlines.h */; }; 1294 1290 53D444DC1DAF08AB00B92784 /* B3WasmAddressValue.h in Headers */ = {isa = PBXBuildFile; fileRef = 53D444DB1DAF08AB00B92784 /* B3WasmAddressValue.h */; }; … … 1430 1426 79B00CBF1C6AB07E0088C65D /* ProxyObject.h in Headers */ = {isa = PBXBuildFile; fileRef = 79B00CBB1C6AB07E0088C65D /* ProxyObject.h */; settings = {ATTRIBUTES = (Private, ); }; }; 1431 1427 79B1788E1D399B8000B1A567 /* JITMathICForwards.h in Headers */ = {isa = PBXBuildFile; fileRef = 79A899FE1D38612E00D18C73 /* JITMathICForwards.h */; settings = {ATTRIBUTES = (Private, ); }; }; 1428 79B759741DFA4C600052174C /* WasmMemoryInformation.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 79B759711DFA4C600052174C /* WasmMemoryInformation.cpp */; }; 1429 79B759751DFA4C600052174C /* WasmMemoryInformation.h in Headers */ = {isa = PBXBuildFile; fileRef = 79B759721DFA4C600052174C /* WasmMemoryInformation.h */; settings = {ATTRIBUTES = (Private, ); }; }; 1430 79B759761DFA4C600052174C /* WasmPageCount.h in Headers */ = {isa = PBXBuildFile; fileRef = 79B759731DFA4C600052174C /* WasmPageCount.h */; settings = {ATTRIBUTES = (Private, ); }; }; 1432 1431 79B819931DD25CF500DDC714 /* JSGlobalObjectInlines.h in Headers */ = {isa = PBXBuildFile; fileRef = 79B819921DD25CF500DDC714 /* JSGlobalObjectInlines.h */; settings = {ATTRIBUTES = (Private, ); }; }; 1433 1432 79C4B15D1BA2158F00FD592E /* DFGLiveCatchVariablePreservationPhase.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 79C4B15B1BA2158F00FD592E /* DFGLiveCatchVariablePreservationPhase.cpp */; }; … … 2379 2378 remoteGlobalIDString = 0F4680A914BA7FD900BFE272; 2380 2379 remoteInfo = "LLInt Offsets"; 2381 };2382 539EB0821D5560F400C82EF7 /* PBXContainerItemProxy */ = {2383 isa = PBXContainerItemProxy;2384 containerPortal = 0867D690FE84028FC02AAC07 /* Project object */;2385 proxyType = 1;2386 remoteGlobalIDString = 539EB0751D55607000C82EF7;2387 remoteInfo = testWASM;2388 2380 }; 2389 2381 5D69E911152BE5470028D720 /* PBXContainerItemProxy */ = { … … 3684 3676 53917E831B791CB8000EBD33 /* TypedArrayPrototype.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; name = TypedArrayPrototype.js; path = builtins/TypedArrayPrototype.js; sourceTree = SOURCE_ROOT; }; 3685 3677 539EB0711D553DF800C82EF7 /* testWasm.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = testWasm.cpp; sourceTree = "<group>"; }; 3686 539EB0801D55607000C82EF7 /* testWASM */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = testWASM; sourceTree = BUILT_PRODUCTS_DIR; };3687 3678 539FB8B91C99DA7C00940FA1 /* JSArrayInlines.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSArrayInlines.h; sourceTree = "<group>"; }; 3688 3679 53D444DB1DAF08AB00B92784 /* B3WasmAddressValue.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = B3WasmAddressValue.h; path = b3/B3WasmAddressValue.h; sourceTree = "<group>"; }; … … 3861 3852 79B00CBA1C6AB07E0088C65D /* ProxyObject.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ProxyObject.cpp; sourceTree = "<group>"; }; 3862 3853 79B00CBB1C6AB07E0088C65D /* ProxyObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ProxyObject.h; sourceTree = "<group>"; }; 3854 79B759711DFA4C600052174C /* WasmMemoryInformation.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WasmMemoryInformation.cpp; sourceTree = "<group>"; }; 3855 79B759721DFA4C600052174C /* WasmMemoryInformation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WasmMemoryInformation.h; sourceTree = "<group>"; }; 3856 79B759731DFA4C600052174C /* WasmPageCount.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WasmPageCount.h; sourceTree = "<group>"; }; 3863 3857 79B819921DD25CF500DDC714 /* JSGlobalObjectInlines.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSGlobalObjectInlines.h; sourceTree = "<group>"; }; 3864 3858 79C4B15B1BA2158F00FD592E /* DFGLiveCatchVariablePreservationPhase.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = DFGLiveCatchVariablePreservationPhase.cpp; path = dfg/DFGLiveCatchVariablePreservationPhase.cpp; sourceTree = "<group>"; }; … … 4912 4906 runOnlyForDeploymentPostprocessing = 0; 4913 4907 }; 4914 539EB0781D55607000C82EF7 /* Frameworks */ = {4915 isa = PBXFrameworksBuildPhase;4916 buildActionMask = 2147483647;4917 files = (4918 539EB0791D55607000C82EF7 /* Foundation.framework in Frameworks */,4919 539EB07A1D55607000C82EF7 /* JavaScriptCore.framework in Frameworks */,4920 );4921 runOnlyForDeploymentPostprocessing = 0;4922 };4923 4908 651122FC14046A4C002B101D /* Frameworks */ = { 4924 4909 isa = PBXFrameworksBuildPhase; … … 4968 4953 0F9327591C20BCBA00CF6564 /* dynbench */, 4969 4954 0F6183431C45F62A0072450B /* testair */, 4970 539EB0801D55607000C82EF7 /* testWASM */,4971 4955 ); 4972 4956 name = Products; … … 6025 6009 535557151D9DFA32006D583B /* WasmMemory.cpp */, 6026 6010 535557131D9D9EA5006D583B /* WasmMemory.h */, 6011 79B759711DFA4C600052174C /* WasmMemoryInformation.cpp */, 6012 79B759721DFA4C600052174C /* WasmMemoryInformation.h */, 6027 6013 53F40E961D5A7BEC0099A1B6 /* WasmModuleParser.cpp */, 6028 6014 53F40E941D5A7AEF0099A1B6 /* WasmModuleParser.h */, 6015 79B759731DFA4C600052174C /* WasmPageCount.h */, 6029 6016 53F40E8C1D5901F20099A1B6 /* WasmParser.h */, 6030 6017 531374BE1D5CE95000AF7A0B /* WasmPlan.cpp */, … … 7984 7971 998ED6751BED768C00DD8017 /* RemoteControllableTarget.h in Headers */, 7985 7972 0F33FCF81C136E2500323F67 /* B3StackmapGenerationParams.h in Headers */, 7973 79B759761DFA4C600052174C /* WasmPageCount.h in Headers */, 7986 7974 0F66E16B14DF3F1600B7B2E4 /* DFGAdjacencyList.h in Headers */, 7987 7975 0FFB921816D02EB20055A5DB /* DFGAllocator.h in Headers */, … … 8223 8211 BC02E90F0E1839DB000F9297 /* ErrorPrototype.h in Headers */, 8224 8212 996B731B1BDA08D100331B84 /* ErrorPrototype.lut.h in Headers */, 8213 79B759751DFA4C600052174C /* WasmMemoryInformation.h in Headers */, 8225 8214 969A07980ED1D3AE00F1F681 /* DirectEvalCodeCache.h in Headers */, 8226 8215 A54982041891D0B00081E5B8 /* EventLoop.h in Headers */, … … 9147 9136 productType = "com.apple.product-type.tool"; 9148 9137 }; 9149 539EB0751D55607000C82EF7 /* testWASM */ = {9150 isa = PBXNativeTarget;9151 buildConfigurationList = 539EB07B1D55607000C82EF7 /* Build configuration list for PBXNativeTarget "testWASM" */;9152 buildPhases = (9153 539EB0761D55607000C82EF7 /* Sources */,9154 539EB0781D55607000C82EF7 /* Frameworks */,9155 );9156 buildRules = (9157 );9158 dependencies = (9159 );9160 name = testWASM;9161 productName = testapi;9162 productReference = 539EB0801D55607000C82EF7 /* testWASM */;9163 productType = "com.apple.product-type.tool";9164 };9165 9138 651122F714046A4C002B101D /* testRegExp */ = { 9166 9139 isa = PBXNativeTarget; … … 9264 9237 0F93274E1C20BCBA00CF6564 /* dynbench */, 9265 9238 0F6183381C45F62A0072450B /* testair */, 9266 539EB0751D55607000C82EF7 /* testWASM */,9267 9239 ); 9268 9240 }; … … 9532 9504 1440F6100A4F85670005F061 /* testapi.c in Sources */, 9533 9505 86D2221A167EF9440024C804 /* testapi.mm in Sources */, 9534 );9535 runOnlyForDeploymentPostprocessing = 0;9536 };9537 539EB0761D55607000C82EF7 /* Sources */ = {9538 isa = PBXSourcesBuildPhase;9539 buildActionMask = 2147483647;9540 files = (9541 539EB0811D55608A00C82EF7 /* testWasm.cpp in Sources */,9542 9506 ); 9543 9507 runOnlyForDeploymentPostprocessing = 0; … … 9648 9612 148F21AA107EC53A0042EC2C /* BytecodeGenerator.cpp in Sources */, 9649 9613 7094C4DE1AE439530041A2EE /* BytecodeIntrinsicRegistry.cpp in Sources */, 9614 79B759741DFA4C600052174C /* WasmMemoryInformation.cpp in Sources */, 9650 9615 C2FCAE1217A9C24E0034C735 /* BytecodeLivenessAnalysis.cpp in Sources */, 9651 9616 0F338E0D1BF0276C0013C88F /* B3DataSection.cpp in Sources */, … … 10472 10437 targetProxy = 0FF922D214F46B2F0041A24E /* PBXContainerItemProxy */; 10473 10438 }; 10474 539EB0831D5560F400C82EF7 /* PBXTargetDependency */ = {10475 isa = PBXTargetDependency;10476 target = 539EB0751D55607000C82EF7 /* testWASM */;10477 targetProxy = 539EB0821D5560F400C82EF7 /* PBXContainerItemProxy */;10478 };10479 10439 5D69E912152BE5470028D720 /* PBXTargetDependency */ = { 10480 10440 isa = PBXTargetDependency; … … 10812 10772 name = Production; 10813 10773 }; 10814 539EB07C1D55607000C82EF7 /* Debug */ = {10815 isa = XCBuildConfiguration;10816 baseConfigurationReference = BC021BF2136900C300FC5467 /* ToolExecutable.xcconfig */;10817 buildSettings = {10818 PRODUCT_NAME = "$(TARGET_NAME)";10819 };10820 name = Debug;10821 };10822 539EB07D1D55607000C82EF7 /* Release */ = {10823 isa = XCBuildConfiguration;10824 baseConfigurationReference = BC021BF2136900C300FC5467 /* ToolExecutable.xcconfig */;10825 buildSettings = {10826 PRODUCT_NAME = "$(TARGET_NAME)";10827 };10828 name = Release;10829 };10830 539EB07E1D55607000C82EF7 /* Profiling */ = {10831 isa = XCBuildConfiguration;10832 baseConfigurationReference = BC021BF2136900C300FC5467 /* ToolExecutable.xcconfig */;10833 buildSettings = {10834 PRODUCT_NAME = "$(TARGET_NAME)";10835 };10836 name = Profiling;10837 };10838 539EB07F1D55607000C82EF7 /* Production */ = {10839 isa = XCBuildConfiguration;10840 baseConfigurationReference = BC021BF2136900C300FC5467 /* ToolExecutable.xcconfig */;10841 buildSettings = {10842 PRODUCT_NAME = "$(TARGET_NAME)";10843 };10844 name = Production;10845 };10846 10774 5D6B2A48152B9E17005231DE /* Debug */ = { 10847 10775 isa = XCBuildConfiguration; … … 11135 11063 defaultConfigurationName = Production; 11136 11064 }; 11137 539EB07B1D55607000C82EF7 /* Build configuration list for PBXNativeTarget "testWASM" */ = {11138 isa = XCConfigurationList;11139 buildConfigurations = (11140 539EB07C1D55607000C82EF7 /* Debug */,11141 539EB07D1D55607000C82EF7 /* Release */,11142 539EB07E1D55607000C82EF7 /* Profiling */,11143 539EB07F1D55607000C82EF7 /* Production */,11144 );11145 defaultConfigurationIsVisible = 0;11146 defaultConfigurationName = Production;11147 };11148 11065 5D6B2A4C152B9E17005231DE /* Build configuration list for PBXAggregateTarget "Test Tools" */ = { 11149 11066 isa = XCConfigurationList; -
trunk/Source/JavaScriptCore/jsc.cpp
r209627 r209630 70 70 #include "TypeProfilerLog.h" 71 71 #include "WasmPlan.h" 72 #include "WasmMemory.h" 72 73 #include <locale.h> 73 74 #include <math.h> … … 2633 2634 } 2634 2635 2636 void* memoryBytes = nullptr; 2637 uint32_t memorySize = 0; 2638 std::unique_ptr<Wasm::Memory> memory; 2639 std::unique_ptr<Wasm::ModuleInformation> moduleInformation = plan.takeModuleInformation(); 2640 2641 if (!!moduleInformation->memory) { 2642 memory = std::make_unique<Wasm::Memory>(moduleInformation->memory.initial(), moduleInformation->memory.maximum()); 2643 memoryBytes = memory->memory(); 2644 memorySize = memory->size(); 2645 } 2646 vm.topWasmMemoryPointer = memoryBytes; 2647 vm.topWasmMemorySize = memorySize; 2648 2635 2649 for (uint32_t i = 0; i < functionCount; ++i) { 2636 2650 JSArray* testCases = jsCast<JSArray*>(exec->argument(i + 2)); -
trunk/Source/JavaScriptCore/runtime/VM.h
r209570 r209630 297 297 ExecState* topCallFrame; 298 298 JSWebAssemblyInstance* topJSWebAssemblyInstance; 299 void* topWasmMemoryPointer; 300 uint32_t topWasmMemorySize; 299 301 Strong<Structure> structureStructure; 300 302 Strong<Structure> structureRareDataStructure; -
trunk/Source/JavaScriptCore/shell/CMakeLists.txt
r207831 r209630 50 50 ) 51 51 52 set(TESTWASM_SOURCES53 ../testWasm.cpp54 )55 56 52 add_executable(testb3 ${TESTB3_SOURCES}) 57 53 target_link_libraries(testb3 ${JSC_LIBRARIES}) … … 60 56 target_link_libraries(testair ${JSC_LIBRARIES}) 61 57 62 add_executable(testWASM ${TESTWASM_SOURCES})63 target_link_libraries(testWASM ${JSC_LIBRARIES})64 65 58 endif () -
trunk/Source/JavaScriptCore/wasm/WasmB3IRGenerator.cpp
r209560 r209630 131 131 static constexpr ExpressionType emptyExpression = nullptr; 132 132 133 B3IRGenerator(Memory *, Procedure&, WasmInternalFunction*, Vector<UnlinkedWasmToWasmCall>&);133 B3IRGenerator(MemoryInformation&, Procedure&, WasmInternalFunction*, Vector<UnlinkedWasmToWasmCall>&); 134 134 135 135 bool WARN_UNUSED_RETURN addArguments(const Vector<Type>&); … … 180 180 Value* zeroForType(Type); 181 181 182 Memory* m_memory;183 182 Procedure& m_proc; 184 183 BasicBlock* m_currentBlock; … … 190 189 }; 191 190 192 B3IRGenerator::B3IRGenerator(Memory* memory, Procedure& procedure, WasmInternalFunction* compilation, Vector<UnlinkedWasmToWasmCall>& unlinkedWasmToWasmCalls) 193 : m_memory(memory) 194 , m_proc(procedure) 191 B3IRGenerator::B3IRGenerator(MemoryInformation& memory, Procedure& procedure, WasmInternalFunction* compilation, Vector<UnlinkedWasmToWasmCall>& unlinkedWasmToWasmCalls) 192 : m_proc(procedure) 195 193 , m_unlinkedWasmToWasmCalls(unlinkedWasmToWasmCalls) 196 194 { … … 211 209 } 212 210 213 if ( m_memory) {214 m_memoryBaseGPR = m _memory->pinnedRegisters().baseMemoryPointer;211 if (!!memory) { 212 m_memoryBaseGPR = memory.pinnedRegisters().baseMemoryPointer; 215 213 m_proc.pinRegister(m_memoryBaseGPR); 216 ASSERT(!m _memory->pinnedRegisters().sizeRegisters[0].sizeOffset);217 m_memorySizeGPR = m _memory->pinnedRegisters().sizeRegisters[0].sizeRegister;218 for (const PinnedSizeRegisterInfo& info : m _memory->pinnedRegisters().sizeRegisters)214 ASSERT(!memory.pinnedRegisters().sizeRegisters[0].sizeOffset); 215 m_memorySizeGPR = memory.pinnedRegisters().sizeRegisters[0].sizeRegister; 216 for (const PinnedSizeRegisterInfo& info : memory.pinnedRegisters().sizeRegisters) 219 217 m_proc.pinRegister(info.sizeRegister); 220 218 … … 303 301 case LoadOpType::I64Load32S: 304 302 case LoadOpType::I64Load32U: 303 case LoadOpType::F32Load: 305 304 return 4; 306 305 case LoadOpType::I64Load: 306 case LoadOpType::F64Load: 307 307 return 8; 308 308 case LoadOpType::I32Load16U: 309 309 case LoadOpType::I64Load16U: 310 case LoadOpType::F32Load:311 case LoadOpType::F64Load:312 310 break; 313 311 } … … 660 658 } 661 659 662 static std::unique_ptr<Compilation> createJSToWasmWrapper(VM& vm, const Signature* signature, MacroAssemblerCodePtr mainFunction, Memory *memory)660 static std::unique_ptr<Compilation> createJSToWasmWrapper(VM& vm, const Signature* signature, MacroAssemblerCodePtr mainFunction, MemoryInformation& memory) 663 661 { 664 662 Procedure proc; … … 682 680 Value* baseMemory = nullptr; 683 681 Vector<Value*> sizes; 684 if (memory) { 685 baseMemory = block->appendNew<ConstPtrValue>(proc, Origin(), memory->memory()); 682 if (!!memory) { 683 baseMemory = block->appendNew<MemoryValue>(proc, Load, Int64, Origin(), 684 block->appendNew<ConstPtrValue>(proc, Origin(), &vm.topWasmMemoryPointer)); 686 685 Value* size = block->appendNew<MemoryValue>(proc, Load, Int32, Origin(), 687 block->appendNew<ConstPtrValue>(proc, Origin(), bitwise_cast<char*>(memory) + Memory::offsetOfSize()));688 sizes.reserveCapacity(memory ->pinnedRegisters().sizeRegisters.size());689 for (auto info : memory ->pinnedRegisters().sizeRegisters) {686 block->appendNew<ConstPtrValue>(proc, Origin(), &vm.topWasmMemorySize)); 687 sizes.reserveCapacity(memory.pinnedRegisters().sizeRegisters.size()); 688 for (auto info : memory.pinnedRegisters().sizeRegisters) { 690 689 sizes.append(block->appendNew<Value>(proc, Sub, Origin(), size, 691 690 block->appendNew<Const32Value>(proc, Origin(), info.sizeOffset))); … … 701 700 // Move the arguments into place. 702 701 Value* result = wasmCallingConvention().setupCall(proc, block, Origin(), arguments, toB3Type(signature->returnType), [&] (PatchpointValue* patchpoint) { 703 if ( memory) {704 ASSERT(sizes.size() == memory ->pinnedRegisters().sizeRegisters.size());705 patchpoint->append(ConstrainedValue(baseMemory, ValueRep::reg(memory ->pinnedRegisters().baseMemoryPointer)));702 if (!!memory) { 703 ASSERT(sizes.size() == memory.pinnedRegisters().sizeRegisters.size()); 704 patchpoint->append(ConstrainedValue(baseMemory, ValueRep::reg(memory.pinnedRegisters().baseMemoryPointer))); 706 705 for (unsigned i = 0; i < sizes.size(); ++i) 707 patchpoint->append(ConstrainedValue(sizes[i], ValueRep::reg(memory ->pinnedRegisters().sizeRegisters[i].sizeRegister)));706 patchpoint->append(ConstrainedValue(sizes[i], ValueRep::reg(memory.pinnedRegisters().sizeRegisters[i].sizeRegister))); 708 707 } 709 708 … … 739 738 } 740 739 741 std::unique_ptr<WasmInternalFunction> parseAndCompile(VM& vm, const uint8_t* functionStart, size_t functionLength, Memory *memory, const Signature* signature, Vector<UnlinkedWasmToWasmCall>& unlinkedWasmToWasmCalls, const FunctionIndexSpace& functionIndexSpace, unsigned optLevel)740 std::unique_ptr<WasmInternalFunction> parseAndCompile(VM& vm, const uint8_t* functionStart, size_t functionLength, MemoryInformation& memory, const Signature* signature, Vector<UnlinkedWasmToWasmCall>& unlinkedWasmToWasmCalls, const FunctionIndexSpace& functionIndexSpace, unsigned optLevel) 742 741 { 743 742 auto result = std::make_unique<WasmInternalFunction>(); -
trunk/Source/JavaScriptCore/wasm/WasmB3IRGenerator.h
r209560 r209630 36 36 namespace JSC { namespace Wasm { 37 37 38 class Memory ;38 class MemoryInformation; 39 39 40 std::unique_ptr<WasmInternalFunction> parseAndCompile(VM&, const uint8_t*, size_t, Memory *, const Signature*, Vector<UnlinkedWasmToWasmCall>&, const FunctionIndexSpace&, unsigned optLevel = 1);40 std::unique_ptr<WasmInternalFunction> parseAndCompile(VM&, const uint8_t*, size_t, MemoryInformation&, const Signature*, Vector<UnlinkedWasmToWasmCall>&, const FunctionIndexSpace&, unsigned optLevel = 1); 41 41 42 42 } } // namespace JSC::Wasm -
trunk/Source/JavaScriptCore/wasm/WasmFormat.cpp
r209306 r209630 34 34 namespace JSC { namespace Wasm { 35 35 36 ModuleInformation::~ModuleInformation() { }37 38 36 } } // namespace JSC::Wasm 39 37 -
trunk/Source/JavaScriptCore/wasm/WasmFormat.h
r209560 r209630 33 33 #include "Identifier.h" 34 34 #include "MacroAssemblerCodeRef.h" 35 #include "WasmMemoryInformation.h" 35 36 #include "WasmOps.h" 37 #include "WasmPageCount.h" 36 38 #include <wtf/Vector.h> 37 39 … … 96 98 }; 97 99 98 class Memory;99 100 100 struct Export { 101 101 Identifier field; … … 104 104 uint32_t functionIndex; 105 105 // FIXME implement Table https://bugs.webkit.org/show_bug.cgi?id=164135 106 // FIXME implement Memory https://bugs.webkit.org/show_bug.cgi?id=16 4134106 // FIXME implement Memory https://bugs.webkit.org/show_bug.cgi?id=165671 107 107 // FIXME implement Global https://bugs.webkit.org/show_bug.cgi?id=164133 108 108 }; … … 120 120 Vector<Signature*> importFunctions; 121 121 // FIXME implement import Table https://bugs.webkit.org/show_bug.cgi?id=164135 122 // FIXME implement import Memory https://bugs.webkit.org/show_bug.cgi?id=164134123 122 // FIXME implement import Global https://bugs.webkit.org/show_bug.cgi?id=164133 124 123 Vector<Signature*> internalFunctionSignatures; 125 std::unique_ptr<Memory>memory;124 MemoryInformation memory; 126 125 Vector<Export> exports; 127 128 ~ModuleInformation();129 126 }; 130 127 -
trunk/Source/JavaScriptCore/wasm/WasmMemory.cpp
r207693 r209630 31 31 namespace JSC { namespace Wasm { 32 32 33 Memory::Memory( uint32_t startingSize, uint32_t capacity, const Vector<unsigned>& pinnedSizeRegisters)33 Memory::Memory(PageCount initial, PageCount maximum) 34 34 : m_mode(Mode::BoundsChecking) 35 , m_size(startingSize) 36 , m_capacity(capacity) 35 , m_size(initial.bytes()) 36 , m_capacity(maximum ? maximum.bytes() : PageCount::max().bytes()) 37 , m_initial(initial) 38 , m_maximum(maximum) 37 39 // FIXME: If we add signal based bounds checking then we need extra space for overflow on load. 38 40 // see: https://bugs.webkit.org/show_bug.cgi?id=162693 39 , m_mappedCapacity( static_cast<uint64_t>(maxPageCount) * static_cast<uint64_t>(pageSize))41 , m_mappedCapacity(PageCount::max().bytes()) 40 42 { 41 ASSERT(pinnedSizeRegisters.size() > 0);43 RELEASE_ASSERT(!maximum || maximum >= initial); // This should be guaranteed by our caller. 42 44 43 45 // FIXME: It would be nice if we had a VM tag for wasm memory. https://bugs.webkit.org/show_bug.cgi?id=163600 … … 51 53 } 52 54 53 ASSERT( startingSize <= m_mappedCapacity);54 if (mprotect(result, startingSize, PROT_READ | PROT_WRITE)) {55 ASSERT(m_size <= m_mappedCapacity); 56 if (mprotect(result, m_size, PROT_READ | PROT_WRITE)) { 55 57 munmap(result, m_mappedCapacity); 56 58 return; 57 59 } 58 60 59 unsigned remainingPinnedRegisters = pinnedSizeRegisters.size() + 1;60 jscCallingConvention().m_calleeSaveRegisters.forEach([&] (Reg reg) {61 GPRReg gpr = reg.gpr();62 if (!remainingPinnedRegisters || RegisterSet::stackRegisters().get(reg))63 return;64 if (remainingPinnedRegisters == 1) {65 m_pinnedRegisters.baseMemoryPointer = gpr;66 remainingPinnedRegisters--;67 } else68 m_pinnedRegisters.sizeRegisters.append({ gpr, pinnedSizeRegisters[--remainingPinnedRegisters - 1] });69 });70 71 ASSERT(!remainingPinnedRegisters);72 61 m_memory = result; 73 62 } -
trunk/Source/JavaScriptCore/wasm/WasmMemory.h
r207693 r209630 29 29 30 30 #include "WasmCallingConvention.h" 31 #include "WasmPageCount.h" 31 32 32 33 #include <wtf/Vector.h> 33 34 34 35 namespace JSC { namespace Wasm { 35 36 struct PinnedSizeRegisterInfo {37 GPRReg sizeRegister;38 unsigned sizeOffset;39 };40 41 // FIXME: We should support more than one memory size register. Right now we take a vector with only one42 // entry. Specifically an entry where the sizeOffset == 0. If we have more than one size register,43 // we can have one for each load size class. see: https://bugs.webkit.org/show_bug.cgi?id=16295244 struct PinnedRegisterInfo {45 Vector<PinnedSizeRegisterInfo> sizeRegisters;46 GPRReg baseMemoryPointer;47 };48 49 constexpr uint32_t pageSize = 64 * KB;50 constexpr uint32_t maxPageCount = static_cast<uint32_t>((1ull << 32) / pageSize);51 36 52 37 class Memory { … … 60 45 }; 61 46 62 Memory() = default; 63 Memory(uint32_t startingSize, uint32_t capacity, const Vector<unsigned>& pinnedSizeRegisters); 47 JS_EXPORT_PRIVATE Memory(PageCount initial, PageCount maximum); 64 48 65 49 ~Memory() … … 71 55 void* memory() const { return m_memory; } 72 56 uint32_t size() const { return m_size; } 73 const PinnedRegisterInfo& pinnedRegisters() const { return m_pinnedRegisters; }74 57 75 58 Mode mode() const { return m_mode; } 59 60 PageCount initial() const { return m_initial; } 61 PageCount maximum() const { return m_maximum; } 76 62 77 63 bool grow(uint32_t newSize) … … 85 71 86 72 static ptrdiff_t offsetOfSize() { return OBJECT_OFFSETOF(Memory, m_size); } 73 87 74 88 75 private: 89 76 void* m_memory { nullptr }; 90 PinnedRegisterInfo m_pinnedRegisters;91 77 Mode m_mode; 92 78 uint32_t m_size { 0 }; 93 79 uint32_t m_capacity { 0 }; 80 PageCount m_initial; 81 PageCount m_maximum; 94 82 uint64_t m_mappedCapacity { 0 }; 95 83 }; -
trunk/Source/JavaScriptCore/wasm/WasmModuleParser.cpp
r209560 r209630 31 31 #include "IdentifierInlines.h" 32 32 #include "WasmFormat.h" 33 #include "WasmMemory .h"33 #include "WasmMemoryInformation.h" 34 34 #include "WasmOps.h" 35 35 #include "WasmSections.h" … … 257 257 } 258 258 case External::Memory: { 259 // FIXME https://bugs.webkit.org/show_bug.cgi?id=164134 259 bool isImport = true; 260 if (!parseMemoryHelper(isImport)) 261 return false; 260 262 break; 261 263 } … … 306 308 } 307 309 310 bool ModuleParser::parseMemoryHelper(bool isImport) 311 { 312 // We don't allow redeclaring memory. Either via import or definition. 313 if (m_module->memory) 314 return false; 315 316 uint8_t flags; 317 if (!parseVarUInt1(flags)) 318 return false; 319 320 uint32_t initial; 321 if (!parseVarUInt32(initial)) 322 return false; 323 324 if (!PageCount::isValid(initial)) 325 return false; 326 327 PageCount initialPageCount(initial); 328 329 PageCount maximumPageCount; 330 if (flags) { 331 uint32_t maximum; 332 if (!parseVarUInt32(maximum)) 333 return false; 334 335 if (!PageCount::isValid(maximum)) 336 return false; 337 338 maximumPageCount = PageCount(maximum); 339 if (initialPageCount > maximumPageCount) 340 return false; 341 } 342 343 Vector<unsigned> pinnedSizes = { 0 }; 344 m_module->memory = MemoryInformation(initialPageCount, maximumPageCount, pinnedSizes, isImport); 345 return true; 346 } 347 308 348 bool ModuleParser::parseMemory() 309 349 { … … 315 355 return true; 316 356 317 uint8_t flags; 318 uint32_t size; 319 if (!parseVarUInt1(flags) 320 || !parseVarUInt32(size) 321 || size > maxPageCount) 322 return false; 323 324 uint32_t capacity = maxPageCount; 325 if (flags) { 326 if (!parseVarUInt32(capacity) 327 || size > capacity 328 || capacity > maxPageCount) 329 return false; 330 } 331 332 capacity *= pageSize; 333 size *= pageSize; 334 335 Vector<unsigned> pinnedSizes = { 0 }; 336 m_module->memory = std::make_unique<Memory>(size, capacity, pinnedSizes); 337 return m_module->memory->memory(); 357 // We only allow one memory for now. 358 if (count != 1) 359 return false; 360 361 bool isImport = false; 362 return parseMemoryHelper(isImport); 338 363 } 339 364 … … 373 398 } 374 399 case External::Memory: { 375 // FIXME https://bugs.webkit.org/show_bug.cgi?id=164134400 // FIXME: https://bugs.webkit.org/show_bug.cgi?id=165671 376 401 break; 377 402 } -
trunk/Source/JavaScriptCore/wasm/WasmModuleParser.h
r209560 r209630 79 79 #undef WASM_SECTION_DECLARE_PARSER 80 80 81 bool WARN_UNUSED_RETURN parseMemoryHelper(bool isImport); 82 81 83 VM* m_vm; 82 84 std::unique_ptr<ModuleInformation> m_module; -
trunk/Source/JavaScriptCore/wasm/WasmPlan.cpp
r209560 r209630 117 117 ASSERT(m_functionIndexSpace[functionIndexSpace].signature == signature); 118 118 119 String error = validateFunction(functionStart, functionLength, signature, m_functionIndexSpace );119 String error = validateFunction(functionStart, functionLength, signature, m_functionIndexSpace, m_moduleInformation->memory); 120 120 if (!error.isNull()) { 121 121 if (verbose) { … … 129 129 130 130 unlinkedWasmToWasmCalls.uncheckedAppend(Vector<UnlinkedWasmToWasmCall>()); 131 m_wasmInternalFunctions.uncheckedAppend(parseAndCompile(*m_vm, functionStart, functionLength, m_moduleInformation->memory .get(), signature, unlinkedWasmToWasmCalls.at(functionIndex), m_functionIndexSpace));131 m_wasmInternalFunctions.uncheckedAppend(parseAndCompile(*m_vm, functionStart, functionLength, m_moduleInformation->memory, signature, unlinkedWasmToWasmCalls.at(functionIndex), m_functionIndexSpace)); 132 132 m_functionIndexSpace[functionIndexSpace].code = m_wasmInternalFunctions[functionIndex]->code->code().executableAddress(); 133 133 } -
trunk/Source/JavaScriptCore/wasm/WasmPlan.h
r209560 r209630 43 43 namespace Wasm { 44 44 45 class Memory;46 47 45 class Plan { 48 46 public: … … 68 66 } 69 67 70 const Memory* memory() const71 {72 RELEASE_ASSERT(!failed());73 return m_moduleInformation->memory.get();74 }75 76 68 size_t internalFunctionCount() const 77 69 { … … 79 71 return m_wasmInternalFunctions.size(); 80 72 } 73 81 74 B3::Compilation* jsToWasmEntryPointForFunction(size_t i) const 82 75 { -
trunk/Source/JavaScriptCore/wasm/WasmValidate.cpp
r209560 r209630 116 116 void dump(const Vector<ControlEntry>& controlStack, const ExpressionList& expressionStack); 117 117 118 bool hasMemory() const { return !!m_memory; } 119 118 120 void setErrorMessage(String&& message) { ASSERT(m_errorMessage.isNull()); m_errorMessage = WTFMove(message); } 119 121 String errorMessage() const { return m_errorMessage; } 120 Validate(ExpressionType returnType )122 Validate(ExpressionType returnType, const MemoryInformation& memory) 121 123 : m_returnType(returnType) 124 , m_memory(memory) 122 125 { 123 126 } … … 132 135 Vector<Type> m_locals; 133 136 String m_errorMessage; 137 const MemoryInformation& m_memory; 134 138 }; 135 139 … … 368 372 } 369 373 370 String validateFunction(const uint8_t* source, size_t length, const Signature* signature, const FunctionIndexSpace& functionIndexSpace )371 { 372 Validate context(signature->returnType );374 String validateFunction(const uint8_t* source, size_t length, const Signature* signature, const FunctionIndexSpace& functionIndexSpace, const MemoryInformation& memory) 375 { 376 Validate context(signature->returnType, memory); 373 377 FunctionParser<Validate> validator(context, source, length, signature, functionIndexSpace); 374 378 if (!validator.parse()) { -
trunk/Source/JavaScriptCore/wasm/WasmValidate.h
r209560 r209630 32 32 namespace JSC { namespace Wasm { 33 33 34 String validateFunction(const uint8_t*, size_t, const Signature*, const FunctionIndexSpace& );34 String validateFunction(const uint8_t*, size_t, const Signature*, const FunctionIndexSpace&, const MemoryInformation&); 35 35 36 36 } } // namespace JSC::Wasm -
trunk/Source/JavaScriptCore/wasm/generateWasmValidateInlinesHeader.py
r208821 r209630 144 144 bool Validate::load(LoadOpType op, ExpressionType pointer, ExpressionType& result, uint32_t) 145 145 { 146 if (!hasMemory()) 147 return false; 148 146 149 switch (op) { 147 150 """ + loadCases + """ … … 151 154 bool Validate::store(StoreOpType op, ExpressionType pointer, ExpressionType value, uint32_t) 152 155 { 156 if (!hasMemory()) 157 return false; 158 153 159 switch (op) { 154 160 """ + storeCases + """ -
trunk/Source/JavaScriptCore/wasm/js/JSWebAssemblyInstance.cpp
r209560 r209630 33 33 #include "JSModuleEnvironment.h" 34 34 #include "JSModuleNamespaceObject.h" 35 #include "JSWebAssemblyMemory.h" 35 36 #include "JSWebAssemblyModule.h" 36 37 #include <wtf/StdLibExtras.h> … … 79 80 visitor.append(&thisObject->m_module); 80 81 visitor.append(&thisObject->m_moduleNamespaceObject); 82 visitor.append(&thisObject->m_memory); 81 83 for (unsigned i = 0; i < thisObject->m_numImportFunctions; ++i) 82 84 visitor.append(thisObject->importFunction(i)); -
trunk/Source/JavaScriptCore/wasm/js/JSWebAssemblyInstance.h
r209560 r209630 30 30 #include "JSDestructibleObject.h" 31 31 #include "JSObject.h" 32 #include "JSWebAssemblyMemory.h" 32 33 33 34 namespace JSC { … … 68 69 } 69 70 70 static size_t offsetOfImportFunctions() 71 { 72 return WTF::roundUpToMultipleOf<sizeof(WriteBarrier<JSCell>)>(sizeof(JSWebAssemblyInstance)); 73 } 71 JSWebAssemblyMemory* memory() { return m_memory.get(); } 72 void setMemory(VM& vm, JSWebAssemblyMemory* memory) { m_memory.set(vm, this, memory); } 74 73 75 74 static size_t offsetOfImportFunction(unsigned idx) 76 75 { 77 76 return offsetOfImportFunctions() + sizeof(WriteBarrier<JSCell>) * idx; 78 }79 80 static size_t allocationSize(unsigned numImportFunctions)81 {82 return offsetOfImportFunctions() + sizeof(WriteBarrier<JSCell>) * numImportFunctions;83 77 } 84 78 … … 89 83 static void visitChildren(JSCell*, SlotVisitor&); 90 84 85 static size_t offsetOfImportFunctions() 86 { 87 return WTF::roundUpToMultipleOf<sizeof(WriteBarrier<JSCell>)>(sizeof(JSWebAssemblyInstance)); 88 } 89 90 static size_t allocationSize(unsigned numImportFunctions) 91 { 92 return offsetOfImportFunctions() + sizeof(WriteBarrier<JSCell>) * numImportFunctions; 93 } 94 91 95 private: 92 96 WriteBarrier<JSWebAssemblyModule> m_module; 93 97 WriteBarrier<JSModuleNamespaceObject> m_moduleNamespaceObject; 98 WriteBarrier<JSWebAssemblyMemory> m_memory; 94 99 unsigned m_numImportFunctions; 95 100 }; -
trunk/Source/JavaScriptCore/wasm/js/JSWebAssemblyMemory.cpp
r207650 r209630 31 31 #include "JSCInlines.h" 32 32 33 #include "JSArrayBuffer.h" 34 #include "ArrayBuffer.h" 35 33 36 namespace JSC { 34 37 35 JSWebAssemblyMemory* JSWebAssemblyMemory::create(VM& vm, Structure* structure) 38 const ClassInfo JSWebAssemblyMemory::s_info = { "WebAssembly.Memory", &Base::s_info, 0, CREATE_METHOD_TABLE(JSWebAssemblyMemory) }; 39 40 JSWebAssemblyMemory* JSWebAssemblyMemory::create(VM& vm, Structure* structure, std::unique_ptr<Wasm::Memory>&& memory) 36 41 { 37 auto* instance = new (NotNull, allocateCell<JSWebAssemblyMemory>(vm.heap)) JSWebAssemblyMemory(vm, structure );42 auto* instance = new (NotNull, allocateCell<JSWebAssemblyMemory>(vm.heap)) JSWebAssemblyMemory(vm, structure, WTFMove(memory)); 38 43 instance->finishCreation(vm); 39 44 return instance; … … 45 50 } 46 51 47 JSWebAssemblyMemory::JSWebAssemblyMemory(VM& vm, Structure* structure )52 JSWebAssemblyMemory::JSWebAssemblyMemory(VM& vm, Structure* structure, std::unique_ptr<Wasm::Memory>&& memory) 48 53 : Base(vm, structure) 54 , m_memory(WTFMove(memory)) 49 55 { 56 } 57 58 JSArrayBuffer* JSWebAssemblyMemory::buffer(VM& vm, JSGlobalObject* globalObject) 59 { 60 if (m_bufferWrapper) 61 return m_bufferWrapper.get(); 62 63 auto destructor = [] (void*) { 64 // We don't need to do anything here to destroy the memory. 65 // The ArrayBuffer backing the JSArrayBuffer is only owned by us, 66 // so we guarantee its lifecylce. 67 }; 68 m_buffer = ArrayBuffer::createFromBytes(memory()->memory(), memory()->size(), WTFMove(destructor)); 69 m_bufferWrapper.set(vm, this, JSArrayBuffer::create(vm, globalObject->m_arrayBufferStructure.get(), m_buffer.get())); 70 RELEASE_ASSERT(m_bufferWrapper); 71 return m_bufferWrapper.get(); 50 72 } 51 73 … … 67 89 68 90 Base::visitChildren(thisObject, visitor); 91 visitor.append(&thisObject->m_bufferWrapper); 69 92 } 70 71 const ClassInfo JSWebAssemblyMemory::s_info = { "WebAssembly.Memory", &Base::s_info, 0, CREATE_METHOD_TABLE(JSWebAssemblyMemory) };72 93 73 94 } // namespace JSC -
trunk/Source/JavaScriptCore/wasm/js/JSWebAssemblyMemory.h
r207650 r209630 30 30 #include "JSDestructibleObject.h" 31 31 #include "JSObject.h" 32 #include "WasmMemory.h" 33 #include <wtf/RefPtr.h> 32 34 33 35 namespace JSC { 36 37 class ArrayBuffer; 38 class JSArrayBuffer; 34 39 35 40 class JSWebAssemblyMemory : public JSDestructibleObject { … … 37 42 typedef JSDestructibleObject Base; 38 43 39 static JSWebAssemblyMemory* create(VM&, Structure* );44 static JSWebAssemblyMemory* create(VM&, Structure*, std::unique_ptr<Wasm::Memory>&&); 40 45 static Structure* createStructure(VM&, JSGlobalObject*, JSValue); 41 46 42 47 DECLARE_INFO; 43 48 49 Wasm::Memory* memory() { return m_memory.get(); } 50 JSArrayBuffer* buffer(VM& vm, JSGlobalObject*); 51 44 52 protected: 45 JSWebAssemblyMemory(VM&, Structure* );53 JSWebAssemblyMemory(VM&, Structure*, std::unique_ptr<Wasm::Memory>&&); 46 54 void finishCreation(VM&); 47 55 static void destroy(JSCell*); 48 56 static void visitChildren(JSCell*, SlotVisitor&); 57 58 std::unique_ptr<Wasm::Memory> m_memory; 59 WriteBarrier<JSArrayBuffer> m_bufferWrapper; 60 RefPtr<ArrayBuffer> m_buffer; 49 61 }; 50 62 -
trunk/Source/JavaScriptCore/wasm/js/WebAssemblyFunction.cpp
r209560 r209630 35 35 #include "JSWebAssemblyCallee.h" 36 36 #include "JSWebAssemblyInstance.h" 37 #include "JSWebAssemblyMemory.h" 37 38 #include "LLIntThunks.h" 38 39 #include "ProtoCallFrame.h" 39 40 #include "VM.h" 40 41 #include "WasmFormat.h" 42 #include "WasmMemory.h" 41 43 42 44 namespace JSC { … … 89 91 remainingArgs++; 90 92 argCount = boxedArgs.size(); 93 } 94 95 // Setup the memory that the entrance loads. 96 if (JSWebAssemblyMemory* memory = wasmFunction->instance()->memory()) { 97 Wasm::Memory* wasmMemory = memory->memory(); 98 vm.topWasmMemoryPointer = wasmMemory->memory(); 99 vm.topWasmMemorySize = wasmMemory->size(); 100 } else { 101 vm.topWasmMemoryPointer = nullptr; 102 vm.topWasmMemorySize = 0; 91 103 } 92 104 -
trunk/Source/JavaScriptCore/wasm/js/WebAssemblyInstanceConstructor.cpp
r209560 r209630 34 34 #include "JSModuleNamespaceObject.h" 35 35 #include "JSWebAssemblyInstance.h" 36 #include "JSWebAssemblyMemory.h" 36 37 #include "JSWebAssemblyModule.h" 37 38 #include "WebAssemblyFunction.h" … … 52 53 */ 53 54 54 static EncodedJSValue JSC_HOST_CALL constructJSWebAssemblyInstance(ExecState* state)55 { 56 auto& vm = state->vm();57 auto scope = DECLARE_THROW_SCOPE(vm);58 auto* globalObject = state->lexicalGlobalObject();55 static EncodedJSValue JSC_HOST_CALL constructJSWebAssemblyInstance(ExecState* exec) 56 { 57 auto& vm = exec->vm(); 58 auto throwScope = DECLARE_THROW_SCOPE(vm); 59 auto* globalObject = exec->lexicalGlobalObject(); 59 60 60 61 // If moduleObject is not a WebAssembly.Module instance, a TypeError is thrown. 61 JSWebAssemblyModule* jsModule = jsDynamicCast<JSWebAssemblyModule*>( state->argument(0));62 JSWebAssemblyModule* jsModule = jsDynamicCast<JSWebAssemblyModule*>(exec->argument(0)); 62 63 if (!jsModule) 63 return JSValue::encode(throwException( state, scope, createTypeError(state, ASCIILiteral("first argument to WebAssembly.Instance must be a WebAssembly.Module"), defaultSourceAppender, runtimeTypeForValue(state->argument(0)))));64 return JSValue::encode(throwException(exec, throwScope, createTypeError(exec, ASCIILiteral("first argument to WebAssembly.Instance must be a WebAssembly.Module"), defaultSourceAppender, runtimeTypeForValue(exec->argument(0))))); 64 65 const Wasm::ModuleInformation& moduleInformation = jsModule->moduleInformation(); 65 66 66 67 // If the importObject parameter is not undefined and Type(importObject) is not Object, a TypeError is thrown. 67 JSValue importArgument = state->argument(1);68 JSValue importArgument = exec->argument(1); 68 69 JSObject* importObject = importArgument.getObject(); 69 70 if (!importArgument.isUndefined() && !importObject) 70 return JSValue::encode(throwException( state, scope, createTypeError(state, ASCIILiteral("second argument to WebAssembly.Instance must be undefined or an Object"), defaultSourceAppender, runtimeTypeForValue(importArgument))));71 return JSValue::encode(throwException(exec, throwScope, createTypeError(exec, ASCIILiteral("second argument to WebAssembly.Instance must be undefined or an Object"), defaultSourceAppender, runtimeTypeForValue(importArgument)))); 71 72 72 73 // If the list of module.imports is not empty and Type(importObject) is not Object, a TypeError is thrown. 73 74 if (moduleInformation.imports.size() && !importObject) 74 return JSValue::encode(throwException( state, scope, createTypeError(state, ASCIILiteral("second argument to WebAssembly.Instance must be Object because the WebAssembly.Module has imports"), defaultSourceAppender, runtimeTypeForValue(importArgument))));75 return JSValue::encode(throwException(exec, throwScope, createTypeError(exec, ASCIILiteral("second argument to WebAssembly.Instance must be Object because the WebAssembly.Module has imports"), defaultSourceAppender, runtimeTypeForValue(importArgument)))); 75 76 76 77 Identifier moduleKey = Identifier::fromUid(PrivateName(PrivateName::Description, "WebAssemblyInstance")); 77 WebAssemblyModuleRecord* moduleRecord = WebAssemblyModuleRecord::create( state, vm, globalObject->webAssemblyModuleRecordStructure(), moduleKey, moduleInformation);78 RETURN_IF_EXCEPTION( scope, { });79 80 Structure* instanceStructure = InternalFunction::createSubclassStructure( state, state->newTarget(), globalObject->WebAssemblyInstanceStructure());81 RETURN_IF_EXCEPTION( scope, { });82 83 JSWebAssemblyInstance* instance = JSWebAssemblyInstance::create(vm, instanceStructure, jsModule, moduleRecord->getModuleNamespace( state), moduleInformation.imports.size());84 RETURN_IF_EXCEPTION( scope, { });78 WebAssemblyModuleRecord* moduleRecord = WebAssemblyModuleRecord::create(exec, vm, globalObject->webAssemblyModuleRecordStructure(), moduleKey, moduleInformation); 79 RETURN_IF_EXCEPTION(throwScope, { }); 80 81 Structure* instanceStructure = InternalFunction::createSubclassStructure(exec, exec->newTarget(), globalObject->WebAssemblyInstanceStructure()); 82 RETURN_IF_EXCEPTION(throwScope, { }); 83 84 JSWebAssemblyInstance* instance = JSWebAssemblyInstance::create(vm, instanceStructure, jsModule, moduleRecord->getModuleNamespace(exec), moduleInformation.imports.size()); 85 RETURN_IF_EXCEPTION(throwScope, { }); 85 86 86 87 // Let funcs, memories and tables be initially-empty lists of callable JavaScript objects, WebAssembly.Memory objects and WebAssembly.Table objects, respectively. … … 89 90 90 91 // FIXME implement Table https://bugs.webkit.org/show_bug.cgi?id=164135 91 // FIXME implement Memory https://bugs.webkit.org/show_bug.cgi?id=16413492 92 // FIXME implement Global https://bugs.webkit.org/show_bug.cgi?id=164133 93 93 94 bool hasMemoryImport = false; 94 95 // For each import i in module.imports: 95 96 for (auto& import : moduleInformation.imports) { 96 97 // 1. Let o be the resultant value of performing Get(importObject, i.module_name). 97 JSValue importModuleValue = importObject->get( state, import.module);98 RETURN_IF_EXCEPTION( scope, { });98 JSValue importModuleValue = importObject->get(exec, import.module); 99 RETURN_IF_EXCEPTION(throwScope, { }); 99 100 // 2. If Type(o) is not Object, throw a TypeError. 100 101 if (!importModuleValue.isObject()) 101 return JSValue::encode(throwException(state, scope, createTypeError(state, ASCIILiteral("import must be an object"), defaultSourceAppender, runtimeTypeForValue(importModuleValue)))); 102 return JSValue::encode(throwException(exec, throwScope, createTypeError(exec, ASCIILiteral("import must be an object"), defaultSourceAppender, runtimeTypeForValue(importModuleValue)))); 103 102 104 // 3. Let v be the value of performing Get(o, i.item_name) 103 105 JSObject* object = jsCast<JSObject*>(importModuleValue); 104 JSValue value = object->get(state, import.field); 105 RETURN_IF_EXCEPTION(scope, { }); 106 JSValue value = object->get(exec, import.field); 107 RETURN_IF_EXCEPTION(throwScope, { }); 108 106 109 switch (import.kind) { 107 110 case Wasm::External::Function: { … … 109 112 // i. If IsCallable(v) is false, throw a TypeError. 110 113 if (!value.isFunction()) 111 return JSValue::encode(throwException( state, scope, createTypeError(state, ASCIILiteral("import function must be callable"), defaultSourceAppender, runtimeTypeForValue(value))));114 return JSValue::encode(throwException(exec, throwScope, createTypeError(exec, ASCIILiteral("import function must be callable"), defaultSourceAppender, runtimeTypeForValue(value)))); 112 115 JSCell* cell = value.asCell(); 113 116 // ii. If v is an Exported Function Exotic Object: … … 139 142 case Wasm::External::Memory: { 140 143 // 6. If i is a memory import: 141 // FIXME implement Memory https://bugs.webkit.org/show_bug.cgi?id=164134 144 RELEASE_ASSERT(!hasMemoryImport); // This should be guaranteed by a validation failure. 145 RELEASE_ASSERT(moduleInformation.memory); 146 hasMemoryImport = true; 147 JSWebAssemblyMemory* memory = jsDynamicCast<JSWebAssemblyMemory*>(value); 142 148 // i. If v is not a WebAssembly.Memory object, throw a TypeError. 149 if (!memory) 150 return JSValue::encode(throwException(exec, throwScope, createTypeError(exec, ASCIILiteral("Memory import is not an instance of WebAssembly.Memory")))); 151 152 Wasm::PageCount expectedInitial = moduleInformation.memory.initial(); 153 Wasm::PageCount actualInitial = memory->memory()->initial(); 154 if (actualInitial < expectedInitial) 155 return JSValue::encode(throwException(exec, throwScope, createTypeError(exec, ASCIILiteral("Memory import provided an 'initial' that is too small")))); 156 157 if (Wasm::PageCount expectedMaximum = moduleInformation.memory.maximum()) { 158 Wasm::PageCount actualMaximum = memory->memory()->maximum(); 159 if (!actualMaximum) { 160 return JSValue::encode( 161 throwException(exec, throwScope, createTypeError(exec, ASCIILiteral("Memory import did not have a 'maximum' but the module requires that it does")))); 162 } 163 164 if (actualMaximum > expectedMaximum) { 165 return JSValue::encode( 166 throwException(exec, throwScope, createTypeError(exec, ASCIILiteral("Memory imports 'maximum' is larger than the module's expected 'maximum")))); 167 } 168 } 143 169 // ii. Append v to memories. 144 170 // iii. Append v.[[Memory]] to imports. 145 RELEASE_ASSERT_NOT_REACHED();171 instance->setMemory(vm, memory); 146 172 break; 147 173 } … … 158 184 } 159 185 160 moduleRecord->link(state, instance); 161 RETURN_IF_EXCEPTION(scope, { }); 186 { 187 if (!!moduleInformation.memory && moduleInformation.memory.isImport()) { 188 // We should either have an import or we should have thrown an exception. 189 RELEASE_ASSERT(hasMemoryImport); 190 } 191 192 if (moduleInformation.memory && !hasMemoryImport) { 193 RELEASE_ASSERT(!moduleInformation.memory.isImport()); 194 // We create a memory when it's a memory definition. 195 std::unique_ptr<Wasm::Memory> memory = std::make_unique<Wasm::Memory>(moduleInformation.memory.initial(), moduleInformation.memory.maximum()); 196 instance->setMemory(vm, 197 JSWebAssemblyMemory::create(vm, exec->lexicalGlobalObject()->WebAssemblyMemoryStructure(), WTFMove(memory))); 198 } 199 } 200 201 moduleRecord->link(exec, instance); 202 RETURN_IF_EXCEPTION(throwScope, { }); 162 203 if (verbose) 163 204 moduleRecord->dump(); 164 JSValue startResult = moduleRecord->evaluate( state);205 JSValue startResult = moduleRecord->evaluate(exec); 165 206 UNUSED_PARAM(startResult); 166 RETURN_IF_EXCEPTION( scope, { });207 RETURN_IF_EXCEPTION(throwScope, { }); 167 208 168 209 return JSValue::encode(instance); -
trunk/Source/JavaScriptCore/wasm/js/WebAssemblyMemoryConstructor.cpp
r208401 r209630 31 31 #include "FunctionPrototype.h" 32 32 #include "JSCInlines.h" 33 #include "JSWebAssemblyMemory.h" 34 #include "WasmMemory.h" 35 #include "WasmPageCount.h" 33 36 #include "WebAssemblyMemoryPrototype.h" 37 #include <wtf/Optional.h> 34 38 35 39 #include "WebAssemblyMemoryConstructor.lut.h" … … 44 48 */ 45 49 46 static EncodedJSValue JSC_HOST_CALL constructJSWebAssemblyMemory(ExecState* state)50 static EncodedJSValue JSC_HOST_CALL constructJSWebAssemblyMemory(ExecState* exec) 47 51 { 48 VM& vm = state->vm(); 49 auto scope = DECLARE_THROW_SCOPE(vm); 50 // FIXME https://bugs.webkit.org/show_bug.cgi?id=164134 51 return JSValue::encode(throwException(state, scope, createError(state, ASCIILiteral("WebAssembly doesn't yet implement the Memory constructor property")))); 52 VM& vm = exec->vm(); 53 auto throwScope = DECLARE_THROW_SCOPE(vm); 54 if (exec->argumentCount() != 1) 55 return JSValue::encode(throwException(exec, throwScope, createTypeError(exec, ASCIILiteral("WebAssembly.Memory expects exactly one argument")))); 56 57 auto getUint32 = [&] (JSValue value) -> uint32_t { 58 double doubleValue = value.toInteger(exec); 59 RETURN_IF_EXCEPTION(throwScope, { }); 60 if (doubleValue < 0 || doubleValue > UINT_MAX) { 61 throwException(exec, throwScope, 62 createRangeError(exec, ASCIILiteral("WebAssembly.Memory expects the 'initial' and 'maximum' properties to be integers in the range: [0, 2^32 - 1]"))); 63 return 0; 64 } 65 return static_cast<uint32_t>(doubleValue); 66 }; 67 68 JSObject* memoryDescriptor; 69 { 70 JSValue argument = exec->argument(0); 71 if (!argument.isObject()) 72 return JSValue::encode(throwException(exec, throwScope, createTypeError(exec, ASCIILiteral("WebAssembly.Memory expects its first argument to be an object")))); 73 memoryDescriptor = jsCast<JSObject*>(argument); 74 } 75 76 Wasm::PageCount initialPageCount; 77 { 78 Identifier initial = Identifier::fromString(&vm, "initial"); 79 JSValue minSizeValue = memoryDescriptor->get(exec, initial); 80 RETURN_IF_EXCEPTION(throwScope, { }); 81 uint32_t size = getUint32(minSizeValue); 82 RETURN_IF_EXCEPTION(throwScope, { }); 83 if (!Wasm::PageCount::isValid(size)) 84 return JSValue::encode(throwException(exec, throwScope, createRangeError(exec, ASCIILiteral("WebAssembly.Memory 'initial' page count is too large")))); 85 initialPageCount = Wasm::PageCount(size); 86 } 87 88 Wasm::PageCount maximumPageCount; 89 { 90 Identifier maximum = Identifier::fromString(&vm, "maximum"); 91 bool hasProperty = memoryDescriptor->hasProperty(exec, maximum); 92 RETURN_IF_EXCEPTION(throwScope, { }); 93 if (hasProperty) { 94 JSValue maxSizeValue = memoryDescriptor->get(exec, maximum); 95 RETURN_IF_EXCEPTION(throwScope, { }); 96 uint32_t size = getUint32(maxSizeValue); 97 if (!Wasm::PageCount::isValid(size)) 98 return JSValue::encode(throwException(exec, throwScope, createRangeError(exec, ASCIILiteral("WebAssembly.Memory 'maximum' page count is too large")))); 99 RETURN_IF_EXCEPTION(throwScope, { }); 100 maximumPageCount = Wasm::PageCount(size); 101 102 if (initialPageCount > maximumPageCount) { 103 return JSValue::encode(throwException(exec, throwScope, 104 createRangeError(exec, ASCIILiteral("'maximum' page count must be than greater than or equal to the 'initial' page count")))); 105 } 106 } 107 } 108 109 std::unique_ptr<Wasm::Memory> memory = std::make_unique<Wasm::Memory>(initialPageCount, maximumPageCount); 110 111 return JSValue::encode(JSWebAssemblyMemory::create(vm, exec->lexicalGlobalObject()->WebAssemblyMemoryStructure(), WTFMove(memory))); 52 112 } 53 113 … … 55 115 { 56 116 VM& vm = state->vm(); 57 auto scope = DECLARE_THROW_SCOPE(vm);58 return JSValue::encode(throwConstructorCannotBeCalledAsFunctionTypeError(state, scope, "WebAssembly.Memory"));117 auto throwScope = DECLARE_THROW_SCOPE(vm); 118 return JSValue::encode(throwConstructorCannotBeCalledAsFunctionTypeError(state, throwScope, "WebAssembly.Memory")); 59 119 } 60 120 -
trunk/Source/JavaScriptCore/wasm/js/WebAssemblyMemoryPrototype.cpp
r207650 r209630 30 30 31 31 #include "FunctionPrototype.h" 32 #include "JSArrayBuffer.h" 32 33 #include "JSCInlines.h" 34 #include "JSWebAssemblyMemory.h" 33 35 34 36 #include "WebAssemblyMemoryPrototype.lut.h" … … 43 45 */ 44 46 45 WebAssemblyMemoryPrototype* WebAssemblyMemoryPrototype::create(VM& vm, JSGlobalObject*, Structure* structure) 47 static EncodedJSValue JSC_HOST_CALL webAssemblyMemoryProtoFuncBuffer(ExecState*); 48 49 EncodedJSValue JSC_HOST_CALL webAssemblyMemoryProtoFuncBuffer(ExecState* exec) 50 { 51 VM& vm = exec->vm(); 52 auto throwScope = DECLARE_THROW_SCOPE(vm); 53 54 JSWebAssemblyMemory* memory = jsDynamicCast<JSWebAssemblyMemory*>(exec->thisValue()); 55 if (!memory) { 56 return JSValue::encode(throwException(exec, throwScope, 57 createTypeError(exec, ASCIILiteral("WebAssembly.Memory.prototype.buffer getter called with non WebAssembly.Memory |this| value")))); 58 } 59 return JSValue::encode(memory->buffer(exec->vm(), exec->lexicalGlobalObject())); 60 } 61 62 WebAssemblyMemoryPrototype* WebAssemblyMemoryPrototype::create(VM& vm, JSGlobalObject* globalObject, Structure* structure) 46 63 { 47 64 auto* object = new (NotNull, allocateCell<WebAssemblyMemoryPrototype>(vm.heap)) WebAssemblyMemoryPrototype(vm, structure); 48 object->finishCreation(vm );65 object->finishCreation(vm, globalObject); 49 66 return object; 50 67 } … … 55 72 } 56 73 57 void WebAssemblyMemoryPrototype::finishCreation(VM& vm )74 void WebAssemblyMemoryPrototype::finishCreation(VM& vm, JSGlobalObject* globalObject) 58 75 { 59 76 Base::finishCreation(vm); 77 JSC_NATIVE_GETTER("buffer", webAssemblyMemoryProtoFuncBuffer, DontEnum | Accessor); 60 78 } 61 79 -
trunk/Source/JavaScriptCore/wasm/js/WebAssemblyMemoryPrototype.h
r207650 r209630 44 44 45 45 protected: 46 void finishCreation(VM& );46 void finishCreation(VM&, JSGlobalObject*); 47 47 48 48 private: -
trunk/Source/JavaScriptCore/wasm/js/WebAssemblyModuleRecord.cpp
r209560 r209630 80 80 } 81 81 case Wasm::External::Memory: { 82 // FIXME https://bugs.webkit.org/show_bug.cgi?id=16413482 // FIXME: https://bugs.webkit.org/show_bug.cgi?id=165671 83 83 break; 84 84 } … … 141 141 } 142 142 case Wasm::External::Memory: { 143 // FIXME https://bugs.webkit.org/show_bug.cgi?id=164134143 // FIXME: https://bugs.webkit.org/show_bug.cgi?id=165671 144 144 break; 145 145 }
Note:
See TracChangeset
for help on using the changeset viewer.