COMMIT_MESSAGE

 1wasm link error
 2

JSTests/ChangeLog

 12016-12-19 JF Bastien <jfbastien@apple.com>
 2
 3 WebAssembly API: implement WebAssembly.LinkError
 4 https://bugs.webkit.org/show_bug.cgi?id=165805
 5 <rdar://problem/29747874>
 6
 7 Reviewed by NOBODY (OOPS!).
 8
 9 Update all exception sites which now throw WebAssembly.LinkError.
 10
 11 * wasm/js-api/element-data.js:
 12 * wasm/js-api/element.js:
 13 (assert.throws):
 14 * wasm/js-api/global-error.js:
 15 (new.Number):
 16 * wasm/js-api/table.js:
 17 (assert.throws):
 18 (new.WebAssembly.Table):
 19 * wasm/js-api/test_Data.js:
 20 * wasm/js-api/test_basic_api.js:
 21 (const.c.in.constructorProperties.switch):
 22 * wasm/js-api/test_memory.js:
 23 (test):
 24 (test.testMemImportError): Deleted.
 25
1262016-12-19 Mark Lam <mark.lam@apple.com>
227
328 Rolling out r209974 and r209952. They break some websites in mysterious ways. Step 2: Rollout r209952.

JSTests/wasm/js-api/element-data.js

@@const memoryDescription = { initial: memSizeInPages, maximum: memSizeInPages };
3737 table: table,
3838 }
3939 };
40  assert.throws(() => new WebAssembly.Instance(module, imports), RangeError, `Element is trying to set an out of bounds table index`);
 40 assert.throws(() => new WebAssembly.Instance(module, imports), WebAssembly.LinkError, `Element is trying to set an out of bounds table index (evaluating 'new WebAssembly.Instance(module, imports)')`);
4141 // On Element failure, the Data section shouldn't have executed.
4242 const buffer = new Uint8Array(memory.buffer);
4343 for (let idx = 0; idx < memSizeInPages * pageSizeInBytes; ++idx) {

JSTests/wasm/js-api/element.js

@@import * as assert from '../assert.js';
141141
142142 for (let i = 19; i < 19 + 5; i++) {
143143 const table = new WebAssembly.Table({element: "anyfunc", initial: i});
144  badInstantiation(table, RangeError, "Element is trying to set an out of bounds table index");
 144 badInstantiation(table, WebAssembly.LinkError, "Element is trying to set an out of bounds table index (evaluating 'new WebAssembly.Instance(module, {imp: {table: actualTable}})')");
145145 }
146146}

JSTests/wasm/js-api/global-error.js

@@for ( let imp of [undefined, null, {}, () => {}, "number", new Number(4)]) {
185185 bin.trim();
186186
187187 const module = new WebAssembly.Module(bin.get());
188  assert.throws(() => new WebAssembly.Instance(module, { imp: { global: imp } }), TypeError, "imported global must be a number (evaluating 'new WebAssembly.Instance(module, { imp: { global: imp } })')");
 188 assert.throws(() => new WebAssembly.Instance(module, { imp: { global: imp } }), WebAssembly.LinkError, "imported global must be a number (evaluating 'new WebAssembly.Instance(module, { imp: { global: imp } })')");
189189}

JSTests/wasm/js-api/table.js

@@function assertBadTableImport(tableDescription, message) {
189189 .Code()
190190 .End();
191191 const module = new WebAssembly.Module(builder.WebAssembly().get());
192  assert.throws(() => new WebAssembly.Instance(module, {imp: {table}}), TypeError, message);
 192 assert.throws(() => new WebAssembly.Instance(module, {imp: {table}}), WebAssembly.LinkError, message);
193193 }
194194
195195 const badTables = [
196  [{initial: 100, maximum:100, element:"anyfunc"}, new WebAssembly.Table({initial:100, element: "anyfunc"}), "Table import does not have a 'maximum' but the module requires that it does"],
197  [{initial: 100, maximum:100, element:"anyfunc"}, new WebAssembly.Table({initial:100, maximum:101, element: "anyfunc"}), "Imported Table's 'maximum' is larger than the module's expected 'maximum'"],
198  [{initial: 100, element:"anyfunc"}, new WebAssembly.Table({initial:10, element: "anyfunc"}), "Table import provided an 'initial' that is too small"],
199  [{initial: 10, element:"anyfunc"}, new WebAssembly.Table({initial:9, element: "anyfunc"}), "Table import provided an 'initial' that is too small"],
 196 [{initial: 100, maximum:100, element:"anyfunc"}, new WebAssembly.Table({initial:100, element: "anyfunc"}), "Table import does not have a 'maximum' but the module requires that it does (evaluating 'new WebAssembly.Instance(module, {imp: {table}})')"],
 197 [{initial: 100, maximum:100, element:"anyfunc"}, new WebAssembly.Table({initial:100, maximum:101, element: "anyfunc"}), "Imported Table's 'maximum' is larger than the module's expected 'maximum' (evaluating 'new WebAssembly.Instance(module, {imp: {table}})')"],
 198 [{initial: 100, element:"anyfunc"}, new WebAssembly.Table({initial:10, element: "anyfunc"}), "Table import provided an 'initial' that is too small (evaluating 'new WebAssembly.Instance(module, {imp: {table}})')"],
 199 [{initial: 10, element:"anyfunc"}, new WebAssembly.Table({initial:9, element: "anyfunc"}), "Table import provided an 'initial' that is too small (evaluating 'new WebAssembly.Instance(module, {imp: {table}})')"],
200200 ];
201201 for (const [d, t, m] of badTables) {
202202 assertBadTableInstance(d, t, m);

@@function assertBadTableImport(tableDescription, message) {
251251 .Code()
252252 .End();
253253 const module = new WebAssembly.Module(builder.WebAssembly().get());
254  assert.throws(() => new WebAssembly.Instance(module, {imp: {table}}), TypeError, "Table import is not an instance of WebAssembly.Table");
 254 assert.throws(() => new WebAssembly.Instance(module, {imp: {table}}), WebAssembly.LinkError, "Table import is not an instance of WebAssembly.Table (evaluating 'new WebAssembly.Instance(module, {imp: {table}})')");
255255 }
256256 assertBadTable(25);
257257 assertBadTable(new Object);

JSTests/wasm/js-api/test_Data.js

@@const assertMemoryAllZero = memory => {
7575 const bin = builder.WebAssembly().get();
7676 const module = new WebAssembly.Module(bin);
7777 const memory = new WebAssembly.Memory(memoryDescription);
78  assert.throws(() => new WebAssembly.Instance(module, { imp: { memory: memory } }), RangeError, `Invalid data segment initialization: segment of 65537 bytes memory of 65536 bytes, at offset 0, segment is too big`);
 78 assert.throws(() => new WebAssembly.Instance(module, { imp: { memory: memory } }), WebAssembly.LinkError, `Invalid data segment initialization: segment of 65537 bytes memory of 65536 bytes, at offset 0, segment is too big (evaluating 'new WebAssembly.Instance(module, { imp: { memory: memory } })')`);
7979 assertMemoryAllZero(memory);
8080})();
8181

@@const assertMemoryAllZero = memory => {
8989 const bin = builder.WebAssembly().get();
9090 const module = new WebAssembly.Module(bin);
9191 const memory = new WebAssembly.Memory(memoryDescription);
92  assert.throws(() => new WebAssembly.Instance(module, { imp: { memory: memory } }), RangeError, `Invalid data segment initialization: segment of 1 bytes memory of 65536 bytes, at offset 65536, segment writes outside of memory`);
 92 assert.throws(() => new WebAssembly.Instance(module, { imp: { memory: memory } }), WebAssembly.LinkError, `Invalid data segment initialization: segment of 1 bytes memory of 65536 bytes, at offset 65536, segment writes outside of memory (evaluating 'new WebAssembly.Instance(module, { imp: { memory: memory } })')`);
9393 assertMemoryAllZero(memory);
9494})();
9595

@@const assertMemoryAllZero = memory => {
103103 const bin = builder.WebAssembly().get();
104104 const module = new WebAssembly.Module(bin);
105105 const memory = new WebAssembly.Memory(memoryDescription);
106  assert.throws(() => new WebAssembly.Instance(module, { imp: { memory: memory } }), RangeError, `Invalid data segment initialization: segment of 2 bytes memory of 65536 bytes, at offset 65535, segment writes outside of memory`);
 106 assert.throws(() => new WebAssembly.Instance(module, { imp: { memory: memory } }), WebAssembly.LinkError, `Invalid data segment initialization: segment of 2 bytes memory of 65536 bytes, at offset 65535, segment writes outside of memory (evaluating 'new WebAssembly.Instance(module, { imp: { memory: memory } })')`);
107107 assertMemoryAllZero(memory);
108108})();
109109

JSTests/wasm/js-api/test_basic_api.js

@@const constructorProperties = {
2424 "Memory": { typeofvalue: "function", writable: true, configurable: true, enumerable: false, length: 1 },
2525 "Table": { typeofvalue: "function", writable: true, configurable: true, enumerable: false, length: 1 },
2626 "CompileError": { typeofvalue: "function", writable: true, configurable: true, enumerable: false, length: 1 },
 27 "LinkError": { typeofvalue: "function", writable: true, configurable: true, enumerable: false, length: 1 },
2728 "RuntimeError": { typeofvalue: "function", writable: true, configurable: true, enumerable: false, length: 1 },
2829};
2930

@@for (const c in constructorProperties) {
8384 new WebAssembly.Table({initial: 20, maximum: 25, element: "anyfunc"});
8485 break;
8586 case "CompileError":
 87 case "LinkError":
8688 case "RuntimeError": {
8789 const e = new WebAssembly[c];
8890 assert.eq(e instanceof WebAssembly[c], true);

JSTests/wasm/js-api/test_memory.js

@@test(function() {
318318 const bin = builder.WebAssembly().get();
319319 const module = new WebAssembly.Module(bin);
320320
321  function testMemImportError(instanceObj, expectedError) {
322  let threw = false;
323  try {
324  new WebAssembly.Instance(module, instanceObj);
325  } catch(e) {
326  assert.truthy(e instanceof TypeError);
327  threw = true;
328  if (expectedError) {
329  assert.truthy(e.message === expectedError);
330  }
331  }
332  assert.truthy(threw);
333  }
334 
335  testMemImportError(20);
336  testMemImportError({ });
337  testMemImportError({imp: { } });
338  testMemImportError({imp: { memory: 20 } });
339  testMemImportError({imp: { memory: [] } });
340  testMemImportError({imp: { memory: new WebAssembly.Memory({initial: 19, maximum: 25}) } }, "Memory import provided an 'initial' that is too small");
341  testMemImportError({imp: { memory: new WebAssembly.Memory({initial: 20}) } }, "Memory import did not have a 'maximum' but the module requires that it does");
342  testMemImportError({imp: { memory: new WebAssembly.Memory({initial: 20, maximum: 26}) } }, "Memory imports 'maximum' is larger than the module's expected 'maximum");
 321 assert.throws(() => new WebAssembly.Instance(module, 20), TypeError, `second argument to WebAssembly.Instance must be undefined or an Object (evaluating 'new WebAssembly.Instance(module, 20)')`);
 322 assert.throws(() => new WebAssembly.Instance(module, {}), TypeError, `import must be an object (evaluating 'new WebAssembly.Instance(module, {})')`);
 323 assert.throws(() => new WebAssembly.Instance(module, {imp: { } }), WebAssembly.LinkError, `Memory import is not an instance of WebAssembly.Memory (evaluating 'new WebAssembly.Instance(module, {imp: { } })')`);
 324 assert.throws(() => new WebAssembly.Instance(module, {imp: { memory: 20 } }), WebAssembly.LinkError, `Memory import is not an instance of WebAssembly.Memory (evaluating 'new WebAssembly.Instance(module, {imp: { memory: 20 } })')`);
 325 assert.throws(() => new WebAssembly.Instance(module, {imp: { memory: [] } }), WebAssembly.LinkError, `Memory import is not an instance of WebAssembly.Memory (evaluating 'new WebAssembly.Instance(module, {imp: { memory: [] } })')`);
 326 assert.throws(() => new WebAssembly.Instance(module, {imp: { memory: new WebAssembly.Memory({initial: 19, maximum: 25}) } }), WebAssembly.LinkError, `Memory import provided an 'initial' that is too small (evaluating 'new WebAssembly.Instance(module, {imp: { memory: new WebAssembly.Memory({initial: 19, maximum: 25}) } })')`);
 327 assert.throws(() => new WebAssembly.Instance(module, {imp: { memory: new WebAssembly.Memory({initial: 20}) } }), WebAssembly.LinkError, `Memory import did not have a 'maximum' but the module requires that it does (evaluating 'new WebAssembly.Instance(module, {imp: { memory: new WebAssembly.Memory({initial: 20}) } })')`);
 328 assert.throws(() => new WebAssembly.Instance(module, {imp: { memory: new WebAssembly.Memory({initial: 20, maximum: 26}) } }), WebAssembly.LinkError, `Memory imports 'maximum' is larger than the module's expected 'maximum' (evaluating 'new WebAssembly.Instance(module, {imp: { memory: new WebAssembly.Memory({initial: 20, maximum: 26}) } })')`);
343329});
344330
345331test(function() {

@@test(function() {
366352 const module = new WebAssembly.Module(bin);
367353
368354 function testMemImportError(instanceObj, expectedError) {
369  assert.throws(() => new WebAssembly.Instance(module, instanceObj), TypeError, expectedError);
 355 assert.throws(() => new WebAssembly.Instance(module, instanceObj), WebAssembly.LinkError, expectedError);
370356 }
371357
372  testMemImportError({imp: { memory: new WebAssembly.Memory({initial: 19, maximum: 25}) } }, "Memory import provided an 'initial' that is too small");
373  testMemImportError({imp: { memory: new WebAssembly.Memory({initial: 19}) } }, "Memory import provided an 'initial' that is too small");
 358 testMemImportError({imp: { memory: new WebAssembly.Memory({initial: 19, maximum: 25}) } }, "Memory import provided an 'initial' that is too small (evaluating 'new WebAssembly.Instance(module, instanceObj)')");
 359 testMemImportError({imp: { memory: new WebAssembly.Memory({initial: 19}) } }, "Memory import provided an 'initial' that is too small (evaluating 'new WebAssembly.Instance(module, instanceObj)')");
374360
375361 // This should not throw.
376362 new WebAssembly.Instance(module, {imp: {memory: new WebAssembly.Memory({initial:20})}});

Source/JavaScriptCore/CMakeLists.txt

@@set(JavaScriptCore_SOURCES
911911 wasm/js/JSWebAssemblyCallee.cpp
912912 wasm/js/JSWebAssemblyCompileError.cpp
913913 wasm/js/JSWebAssemblyInstance.cpp
 914 wasm/js/JSWebAssemblyLinkError.cpp
914915 wasm/js/JSWebAssemblyMemory.cpp
915916 wasm/js/JSWebAssemblyModule.cpp
916917 wasm/js/JSWebAssemblyRuntimeError.cpp

@@set(JavaScriptCore_SOURCES
920921 wasm/js/WebAssemblyFunction.cpp
921922 wasm/js/WebAssemblyInstanceConstructor.cpp
922923 wasm/js/WebAssemblyInstancePrototype.cpp
 924 wasm/js/WebAssemblyLinkErrorConstructor.cpp
 925 wasm/js/WebAssemblyLinkErrorPrototype.cpp
923926 wasm/js/WebAssemblyMemoryConstructor.cpp
924927 wasm/js/WebAssemblyMemoryPrototype.cpp
925928 wasm/js/WebAssemblyModuleConstructor.cpp

@@set(JavaScriptCore_OBJECT_LUT_SOURCES
987990 wasm/js/WebAssemblyCompileErrorPrototype.cpp
988991 wasm/js/WebAssemblyInstanceConstructor.cpp
989992 wasm/js/WebAssemblyInstancePrototype.cpp
 993 wasm/js/WebAssemblyLinkErrorConstructor.cpp
 994 wasm/js/WebAssemblyLinkErrorPrototype.cpp
990995 wasm/js/WebAssemblyMemoryConstructor.cpp
991996 wasm/js/WebAssemblyMemoryPrototype.cpp
992997 wasm/js/WebAssemblyModuleConstructor.cpp

Source/JavaScriptCore/ChangeLog

 12016-12-19 JF Bastien <jfbastien@apple.com>
 2
 3 WebAssembly API: implement WebAssembly.LinkError
 4 https://bugs.webkit.org/show_bug.cgi?id=165805
 5 <rdar://problem/29747874>
 6
 7 Reviewed by NOBODY (OOPS!).
 8
 9 As described here: https://github.com/WebAssembly/design/pull/901
 10 Some TypeError and RangeError are now converted to WebAssembly.LinkError.
 11
 12 * CMakeLists.txt: add files
 13 * DerivedSources.make: add autoget .lut.h files
 14 * JavaScriptCore.xcodeproj/project.pbxproj: add files
 15 * builtins/BuiltinNames.h: new name LinkError
 16 * runtime/JSGlobalObject.h: auto-register LinkError using existing macro magic
 17 * wasm/JSWebAssembly.h: make the new includes available
 18 * wasm/js/JSWebAssemblyLinkError.cpp: Copied from Source/JavaScriptCore/wasm/JSWebAssemblyCompileError.cpp.
 19 (JSC::JSWebAssemblyLinkError::create):
 20 (JSC::JSWebAssemblyLinkError::JSWebAssemblyLinkError):
 21 (JSC::createWebAssemblyLinkError):
 22 * wasm/js/JSWebAssemblyLinkError.h: Copied from Source/JavaScriptCore/wasm/JSWebAssemblyCompileError.h.
 23 (JSC::JSWebAssemblyLinkError::create):
 24 * wasm/js/WebAssemblyInstanceConstructor.cpp: update as per spec change
 25 (JSC::constructJSWebAssemblyInstance):
 26 * wasm/js/WebAssemblyLinkErrorConstructor.cpp: Copied from Source/JavaScriptCore/wasm/WebAssemblyCompileErrorConstructor.cpp.
 27 (JSC::constructJSWebAssemblyLinkError):
 28 (JSC::callJSWebAssemblyLinkError):
 29 (JSC::WebAssemblyLinkErrorConstructor::create):
 30 (JSC::WebAssemblyLinkErrorConstructor::createStructure):
 31 (JSC::WebAssemblyLinkErrorConstructor::finishCreation):
 32 (JSC::WebAssemblyLinkErrorConstructor::WebAssemblyLinkErrorConstructor):
 33 (JSC::WebAssemblyLinkErrorConstructor::getConstructData):
 34 (JSC::WebAssemblyLinkErrorConstructor::getCallData):
 35 * wasm/js/WebAssemblyLinkErrorConstructor.h: Copied from Source/JavaScriptCore/wasm/WebAssemblyCompileErrorConstructor.h.
 36 * wasm/js/WebAssemblyLinkErrorPrototype.cpp: Copied from Source/JavaScriptCore/wasm/WebAssemblyCompileErrorPrototypr.cpp.
 37 (JSC::WebAssemblyLinkErrorPrototype::create):
 38 (JSC::WebAssemblyLinkErrorPrototype::createStructure):
 39 (JSC::WebAssemblyLinkErrorPrototype::finishCreation):
 40 (JSC::WebAssemblyLinkErrorPrototype::WebAssemblyLinkErrorPrototype):
 41 * wasm/js/WebAssemblyLinkErrorPrototype.h: Copied from Source/JavaScriptCore/wasm/WebAssemblyCompileErrorPrototypr.h.
 42 * wasm/js/WebAssemblyModuleRecord.cpp: update as per spec change
 43 (JSC::dataSegmentFail):
 44 (JSC::WebAssemblyModuleRecord::evaluate):
 45
1462016-12-19 Mark Lam <mark.lam@apple.com>
247
348 Rolling out r209974 and r209952. They break some websites in mysterious ways. Step 2: Rollout r209952.

Source/JavaScriptCore/DerivedSources.make

@@OBJECT_LUT_HEADERS = \
169169 WebAssemblyCompileErrorPrototype.lut.h \
170170 WebAssemblyInstanceConstructor.lut.h \
171171 WebAssemblyInstancePrototype.lut.h \
 172 WebAssemblyLinkErrorConstructor.lut.h \
 173 WebAssemblyLinkErrorPrototype.lut.h \
172174 WebAssemblyMemoryConstructor.lut.h \
173175 WebAssemblyMemoryPrototype.lut.h \
174176 WebAssemblyModuleConstructor.lut.h \

Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj

20272027 ADBC54D51DF8EA2B005BF738 /* WebAssemblyToJSCallee.h in Headers */ = {isa = PBXBuildFile; fileRef = ADBC54D31DF8EA00005BF738 /* WebAssemblyToJSCallee.h */; };
20282028 ADDB1F6318D77DBE009B58A8 /* OpaqueRootSet.h in Headers */ = {isa = PBXBuildFile; fileRef = ADDB1F6218D77DB7009B58A8 /* OpaqueRootSet.h */; settings = {ATTRIBUTES = (Private, ); }; };
20292029 ADE39FFF16DD144B0003CD4A /* PropertyTable.cpp in Sources */ = {isa = PBXBuildFile; fileRef = AD1CF06816DCAB2D00B97123 /* PropertyTable.cpp */; };
 2030 ADE802981E08F1DE0058DE78 /* JSWebAssemblyLinkError.cpp in Sources */ = {isa = PBXBuildFile; fileRef = ADE802931E08F1C90058DE78 /* JSWebAssemblyLinkError.cpp */; };
 2031 ADE802991E08F1DE0058DE78 /* JSWebAssemblyLinkError.h in Headers */ = {isa = PBXBuildFile; fileRef = ADE802941E08F1C90058DE78 /* JSWebAssemblyLinkError.h */; settings = {ATTRIBUTES = (Private, ); }; };
 2032 ADE8029A1E08F1DE0058DE78 /* WebAssemblyLinkErrorConstructor.h in Headers */ = {isa = PBXBuildFile; fileRef = ADE802951E08F1C90058DE78 /* WebAssemblyLinkErrorConstructor.h */; settings = {ATTRIBUTES = (Private, ); }; };
 2033 ADE8029B1E08F1DE0058DE78 /* WebAssemblyLinkErrorPrototype.cpp in Sources */ = {isa = PBXBuildFile; fileRef = ADE802961E08F1C90058DE78 /* WebAssemblyLinkErrorPrototype.cpp */; };
 2034 ADE8029C1E08F1DE0058DE78 /* WebAssemblyLinkErrorPrototype.h in Headers */ = {isa = PBXBuildFile; fileRef = ADE802971E08F1C90058DE78 /* WebAssemblyLinkErrorPrototype.h */; settings = {ATTRIBUTES = (Private, ); }; };
 2035 ADE8029E1E08F2280058DE78 /* WebAssemblyLinkErrorConstructor.cpp in Sources */ = {isa = PBXBuildFile; fileRef = ADE8029D1E08F2260058DE78 /* WebAssemblyLinkErrorConstructor.cpp */; };
20302036 B59F89391891F29F00D5CCDC /* UnlinkedInstructionStream.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B59F89381891ADB500D5CCDC /* UnlinkedInstructionStream.cpp */; };
20312037 BC02E90D0E1839DB000F9297 /* ErrorConstructor.h in Headers */ = {isa = PBXBuildFile; fileRef = BC02E9050E1839DB000F9297 /* ErrorConstructor.h */; };
20322038 BC02E90F0E1839DB000F9297 /* ErrorPrototype.h in Headers */ = {isa = PBXBuildFile; fileRef = BC02E9070E1839DB000F9297 /* ErrorPrototype.h */; settings = {ATTRIBUTES = (Private, ); }; };

45024508 ADBC54D21DF8EA00005BF738 /* WebAssemblyToJSCallee.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = WebAssemblyToJSCallee.cpp; path = js/WebAssemblyToJSCallee.cpp; sourceTree = "<group>"; };
45034509 ADBC54D31DF8EA00005BF738 /* WebAssemblyToJSCallee.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = WebAssemblyToJSCallee.h; path = js/WebAssemblyToJSCallee.h; sourceTree = "<group>"; };
45044510 ADDB1F6218D77DB7009B58A8 /* OpaqueRootSet.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OpaqueRootSet.h; sourceTree = "<group>"; };
 4511 ADE802931E08F1C90058DE78 /* JSWebAssemblyLinkError.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = JSWebAssemblyLinkError.cpp; path = js/JSWebAssemblyLinkError.cpp; sourceTree = "<group>"; };
 4512 ADE802941E08F1C90058DE78 /* JSWebAssemblyLinkError.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = JSWebAssemblyLinkError.h; path = js/JSWebAssemblyLinkError.h; sourceTree = "<group>"; };
 4513 ADE802951E08F1C90058DE78 /* WebAssemblyLinkErrorConstructor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = WebAssemblyLinkErrorConstructor.h; path = js/WebAssemblyLinkErrorConstructor.h; sourceTree = "<group>"; };
 4514 ADE802961E08F1C90058DE78 /* WebAssemblyLinkErrorPrototype.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = WebAssemblyLinkErrorPrototype.cpp; path = js/WebAssemblyLinkErrorPrototype.cpp; sourceTree = "<group>"; };
 4515 ADE802971E08F1C90058DE78 /* WebAssemblyLinkErrorPrototype.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = WebAssemblyLinkErrorPrototype.h; path = js/WebAssemblyLinkErrorPrototype.h; sourceTree = "<group>"; };
 4516 ADE8029D1E08F2260058DE78 /* WebAssemblyLinkErrorConstructor.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = WebAssemblyLinkErrorConstructor.cpp; path = js/WebAssemblyLinkErrorConstructor.cpp; sourceTree = "<group>"; };
45054517 B59F89371891AD3300D5CCDC /* UnlinkedInstructionStream.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UnlinkedInstructionStream.h; sourceTree = "<group>"; };
45064518 B59F89381891ADB500D5CCDC /* UnlinkedInstructionStream.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = UnlinkedInstructionStream.cpp; sourceTree = "<group>"; };
45074519 BC021BF2136900C300FC5467 /* ToolExecutable.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = ToolExecutable.xcconfig; sourceTree = "<group>"; };

75977609 796FB4391DFF8C3F0039C95D /* JSWebAssemblyHelpers.h */,
75987610 AD2FCBA81DB58DA400B3E736 /* JSWebAssemblyInstance.cpp */,
75997611 AD2FCBA91DB58DA400B3E736 /* JSWebAssemblyInstance.h */,
 7612 ADE802931E08F1C90058DE78 /* JSWebAssemblyLinkError.cpp */,
 7613 ADE802941E08F1C90058DE78 /* JSWebAssemblyLinkError.h */,
76007614 AD2FCBAA1DB58DA400B3E736 /* JSWebAssemblyMemory.cpp */,
76017615 AD2FCBAB1DB58DA400B3E736 /* JSWebAssemblyMemory.h */,
76027616 AD2FCB8C1DB5844000B3E736 /* JSWebAssemblyModule.cpp */,

76157629 AD2FCBB51DB58DA400B3E736 /* WebAssemblyInstanceConstructor.h */,
76167630 AD2FCBB61DB58DA400B3E736 /* WebAssemblyInstancePrototype.cpp */,
76177631 AD2FCBB71DB58DA400B3E736 /* WebAssemblyInstancePrototype.h */,
 7632 ADE8029D1E08F2260058DE78 /* WebAssemblyLinkErrorConstructor.cpp */,
 7633 ADE802951E08F1C90058DE78 /* WebAssemblyLinkErrorConstructor.h */,
 7634 ADE802961E08F1C90058DE78 /* WebAssemblyLinkErrorPrototype.cpp */,
 7635 ADE802971E08F1C90058DE78 /* WebAssemblyLinkErrorPrototype.h */,
76187636 AD2FCBB81DB58DA400B3E736 /* WebAssemblyMemoryConstructor.cpp */,
76197637 AD2FCBB91DB58DA400B3E736 /* WebAssemblyMemoryConstructor.h */,
76207638 AD2FCBBA1DB58DA400B3E736 /* WebAssemblyMemoryPrototype.cpp */,

79467964 FE80C1971D775CDD008510C0 /* CatchScope.h in Headers */,
79477965 0F24E54217EA9F5900ABB217 /* CCallHelpers.h in Headers */,
79487966 0F070A471D543A8B006E7232 /* CellContainer.h in Headers */,
 7967 ADE8029A1E08F1DE0058DE78 /* WebAssemblyLinkErrorConstructor.h in Headers */,
79497968 0F070A481D543A90006E7232 /* CellContainerInlines.h in Headers */,
79507969 0F1C3DDA1BBCE09E00E523E4 /* CellState.h in Headers */,
79517970 BC6AAAE50E1F426500AD87D8 /* ClassInfo.h in Headers */,

84228441 A5339EC61BB399A60054F005 /* InspectorHeapAgent.h in Headers */,
84238442 E35E03601B7AB43E0073AD2A /* InspectorInstrumentationObject.h in Headers */,
84248443 E33B3E261B7ABD750048DB2E /* InspectorInstrumentationObject.lut.h in Headers */,
 8444 ADE802991E08F1DE0058DE78 /* JSWebAssemblyLinkError.h in Headers */,
84258445 A532438C18568335002ED692 /* InspectorProtocolObjects.h in Headers */,
84268446 A55D93AC18514F7900400DED /* InspectorProtocolTypes.h in Headers */,
84278447 A50E4B6218809DD50068A46D /* InspectorRuntimeAgent.h in Headers */,

87148734 E328C6C71DA4304500D255FD /* MaxFrameExtentForSlowPathCall.h in Headers */,
87158735 90213E3E123A40C200D422F3 /* MemoryStatistics.h in Headers */,
87168736 0FB5467B14F5C7E1002C2989 /* MethodOfGettingAValueProfile.h in Headers */,
 8737 ADE8029C1E08F1DE0058DE78 /* WebAssemblyLinkErrorPrototype.h in Headers */,
87178738 7C008CE7187631B600955C24 /* Microtask.h in Headers */,
87188739 86C568E211A213EE0007F7F0 /* MIPSAssembler.h in Headers */,
87198740 C4703CD7192844CC0013FBEA /* models.py in Headers */,

98119832 A7D89CFB17A0B8CC00773AD8 /* DFGLivenessAnalysisPhase.cpp in Sources */,
98129833 0FF0F19916B729F6005DF95B /* DFGLongLivedState.cpp in Sources */,
98139834 A767B5B517A0B9650063D940 /* DFGLoopPreHeaderCreationPhase.cpp in Sources */,
 9835 ADE8029E1E08F2280058DE78 /* WebAssemblyLinkErrorConstructor.cpp in Sources */,
98149836 79F8FC1E1B9FED0F00CA66AB /* DFGMaximalFlushInsertionPhase.cpp in Sources */,
98159837 0F5874ED194FEB1200AAB2C1 /* DFGMayExit.cpp in Sources */,
98169838 0F1725FF1B48719A00AC3A55 /* DFGMinifiedGraph.cpp in Sources */,

1009810120 A5C3A1A518C0490200C9593A /* JSGlobalObjectConsoleClient.cpp in Sources */,
1009910121 A59455921824744700CC3843 /* JSGlobalObjectDebuggable.cpp in Sources */,
1010010122 A57D23E91891B0770031C7FA /* JSGlobalObjectDebuggerAgent.cpp in Sources */,
 10123 ADE8029B1E08F1DE0058DE78 /* WebAssemblyLinkErrorPrototype.cpp in Sources */,
1010110124 14E9D17B107EC469004DDA21 /* JSGlobalObjectFunctions.cpp in Sources */,
1010210125 A51007C0187CC3C600B38879 /* JSGlobalObjectInspectorController.cpp in Sources */,
1010310126 A50E4B6318809DD50068A46D /* JSGlobalObjectRuntimeAgent.cpp in Sources */,

1016110184 79E423E21DEE65320078D355 /* JSWebAssemblyCallee.cpp in Sources */,
1016210185 AD2FCBE21DB58DAD00B3E736 /* JSWebAssemblyCompileError.cpp in Sources */,
1016310186 AD2FCBE41DB58DAD00B3E736 /* JSWebAssemblyInstance.cpp in Sources */,
 10187 ADE802981E08F1DE0058DE78 /* JSWebAssemblyLinkError.cpp in Sources */,
1016410188 AD2FCBE61DB58DAD00B3E736 /* JSWebAssemblyMemory.cpp in Sources */,
1016510189 AD2FCC041DB58DAD00B3E736 /* JSWebAssemblyModule.cpp in Sources */,
1016610190 AD2FCBE81DB58DAD00B3E736 /* JSWebAssemblyRuntimeError.cpp in Sources */,

Source/JavaScriptCore/builtins/BuiltinNames.h

@@namespace JSC {
166166 macro(Memory) \
167167 macro(Table) \
168168 macro(CompileError) \
 169 macro(LinkError) \
169170 macro(RuntimeError) \
170171
171172

Source/JavaScriptCore/runtime/JSGlobalObject.h

@@struct HashTable;
140140#define FOR_EACH_WEBASSEMBLY_CONSTRUCTOR_TYPE(macro) \
141141 macro(WebAssemblyCompileError, webAssemblyCompileError, WebAssemblyCompileError, WebAssemblyCompileError, CompileError, error) \
142142 macro(WebAssemblyInstance, webAssemblyInstance, WebAssemblyInstance, WebAssemblyInstance, Instance, object) \
 143 macro(WebAssemblyLinkError, webAssemblyLinkError, WebAssemblyLinkError, WebAssemblyLinkError, LinkError, error) \
143144 macro(WebAssemblyMemory, webAssemblyMemory, WebAssemblyMemory, WebAssemblyMemory, Memory, object) \
144145 macro(WebAssemblyModule, webAssemblyModule, WebAssemblyModule, WebAssemblyModule, Module, object) \
145146 macro(WebAssemblyRuntimeError, webAssemblyRuntimeError, WebAssemblyRuntimeError, WebAssemblyRuntimeError, RuntimeError, error) \

Source/JavaScriptCore/wasm/JSWebAssembly.h

3131#include "js/JSWebAssemblyCallee.h"
3232#include "js/JSWebAssemblyCompileError.h"
3333#include "js/JSWebAssemblyInstance.h"
 34#include "js/JSWebAssemblyLinkError.h"
3435#include "js/JSWebAssemblyMemory.h"
3536#include "js/JSWebAssemblyModule.h"
3637#include "js/JSWebAssemblyRuntimeError.h"

4041#include "js/WebAssemblyFunction.h"
4142#include "js/WebAssemblyInstanceConstructor.h"
4243#include "js/WebAssemblyInstancePrototype.h"
 44#include "js/WebAssemblyLinkErrorConstructor.h"
 45#include "js/WebAssemblyLinkErrorPrototype.h"
4346#include "js/WebAssemblyMemoryConstructor.h"
4447#include "js/WebAssemblyMemoryPrototype.h"
4548#include "js/WebAssemblyModuleConstructor.h"

Source/JavaScriptCore/wasm/js/JSWebAssemblyLinkError.cpp

 1/*
 2 * Copyright (C) 2016 Apple Inc. All rights reserved.
 3 *
 4 * Redistribution and use in source and binary forms, with or without
 5 * modification, are permitted provided that the following conditions
 6 * are met:
 7 * 1. Redistributions of source code must retain the above copyright
 8 * notice, this list of conditions and the following disclaimer.
 9 * 2. Redistributions in binary form must reproduce the above copyright
 10 * notice, this list of conditions and the following disclaimer in the
 11 * documentation and/or other materials provided with the distribution.
 12 *
 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 24 */
 25
 26#include "config.h"
 27#include "JSWebAssemblyLinkError.h"
 28
 29#if ENABLE(WEBASSEMBLY)
 30
 31#include "JSCInlines.h"
 32
 33namespace JSC {
 34
 35JSWebAssemblyLinkError* JSWebAssemblyLinkError::create(ExecState* state, Structure* structure, const String& message, bool useCurrentFrame)
 36{
 37 auto& vm = state->vm();
 38 auto* instance = new (NotNull, allocateCell<JSWebAssemblyLinkError>(vm.heap)) JSWebAssemblyLinkError(vm, structure);
 39 instance->finishCreation(state, vm, message, useCurrentFrame);
 40 return instance;
 41}
 42
 43JSWebAssemblyLinkError::JSWebAssemblyLinkError(VM& vm, Structure* structure)
 44 : Base(vm, structure)
 45{
 46}
 47
 48const ClassInfo JSWebAssemblyLinkError::s_info = { "WebAssembly.LinkError", &Base::s_info, 0, CREATE_METHOD_TABLE(JSWebAssemblyLinkError) };
 49
 50
 51JSObject* createWebAssemblyLinkError(ExecState* exec, const String& message)
 52{
 53 ASSERT(!message.isEmpty());
 54 JSGlobalObject* globalObject = exec->lexicalGlobalObject();
 55 return ErrorInstance::create(exec, globalObject->vm(), globalObject->WebAssemblyLinkErrorStructure(), message, defaultSourceAppender, TypeNothing, true);
 56}
 57
 58} // namespace JSC
 59
 60#endif // ENABLE(WEBASSEMBLY)

Source/JavaScriptCore/wasm/js/JSWebAssemblyLinkError.h

 1/*
 2 * Copyright (C) 2016 Apple Inc. All rights reserved.
 3 *
 4 * Redistribution and use in source and binary forms, with or without
 5 * modification, are permitted provided that the following conditions
 6 * are met:
 7 * 1. Redistributions of source code must retain the above copyright
 8 * notice, this list of conditions and the following disclaimer.
 9 * 2. Redistributions in binary form must reproduce the above copyright
 10 * notice, this list of conditions and the following disclaimer in the
 11 * documentation and/or other materials provided with the distribution.
 12 *
 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 24 */
 25
 26#pragma once
 27
 28#if ENABLE(WEBASSEMBLY)
 29
 30#include "ErrorInstance.h"
 31
 32namespace JSC {
 33
 34class JSWebAssemblyLinkError : public ErrorInstance {
 35public:
 36 typedef ErrorInstance Base;
 37
 38 static JSWebAssemblyLinkError* create(ExecState*, Structure*, const String&, bool);
 39 static JSWebAssemblyLinkError* create(ExecState* exec, Structure* structure, JSValue message, bool useCurrentFrame)
 40 {
 41 return create(exec, structure, message.isUndefined() ? String() : message.toWTFString(exec), useCurrentFrame);
 42 }
 43
 44 DECLARE_INFO;
 45
 46protected:
 47 JSWebAssemblyLinkError(VM&, Structure*);
 48};
 49
 50JSObject* createWebAssemblyLinkError(ExecState*, const String&);
 51
 52} // namespace JSC
 53
 54#endif // ENABLE(WEBASSEMBLY)

Source/JavaScriptCore/wasm/js/WebAssemblyInstanceConstructor.cpp

3333#include "JSModuleEnvironment.h"
3434#include "JSModuleNamespaceObject.h"
3535#include "JSWebAssemblyInstance.h"
 36#include "JSWebAssemblyLinkError.h"
3637#include "JSWebAssemblyMemory.h"
3738#include "JSWebAssemblyModule.h"
3839#include "WebAssemblyFunction.h"

@@static EncodedJSValue JSC_HOST_CALL constructJSWebAssemblyInstance(ExecState* ex
108109 switch (import.kind) {
109110 case Wasm::ExternalKind::Function: {
110111 // 4. If i is a function import:
111  // i. If IsCallable(v) is false, throw a TypeError.
 112 // i. If IsCallable(v) is false, throw a WebAssembly.LinkError.
112113 if (!value.isFunction())
113  return JSValue::encode(throwException(exec, throwScope, createTypeError(exec, ASCIILiteral("import function must be callable"), defaultSourceAppender, runtimeTypeForValue(value))));
 114 return JSValue::encode(throwException(exec, throwScope, createWebAssemblyLinkError(exec, ASCIILiteral("import function must be callable"))));
114115 JSCell* cell = value.asCell();
115116 // ii. If v is an Exported Function Exotic Object:
116117 if (WebAssemblyFunction* importedExports = jsDynamicCast<WebAssemblyFunction*>(object)) {

@@static EncodedJSValue JSC_HOST_CALL constructJSWebAssemblyInstance(ExecState* ex
134135 // 7. Otherwise (i is a table import):
135136 hasTableImport = true;
136137 JSWebAssemblyTable* table = jsDynamicCast<JSWebAssemblyTable*>(value);
137  // i. If v is not a WebAssembly.Table object, throw a TypeError.
 138 // i. If v is not a WebAssembly.Table object, throw a WebAssembly.LinkError.
138139 if (!table)
139  return JSValue::encode(throwException(exec, throwScope, createTypeError(exec, ASCIILiteral("Table import is not an instance of WebAssembly.Table"))));
 140 return JSValue::encode(throwException(exec, throwScope, createWebAssemblyLinkError(exec, ASCIILiteral("Table import is not an instance of WebAssembly.Table"))));
140141
141142 uint32_t expectedInitial = moduleInformation.tableInformation.initial();
142143 uint32_t actualInitial = table->size();
143144 if (actualInitial < expectedInitial)
144  return JSValue::encode(throwException(exec, throwScope, createTypeError(exec, ASCIILiteral("Table import provided an 'initial' that is too small"))));
 145 return JSValue::encode(throwException(exec, throwScope, createWebAssemblyLinkError(exec, ASCIILiteral("Table import provided an 'initial' that is too small"))));
145146
146147 if (std::optional<uint32_t> expectedMaximum = moduleInformation.tableInformation.maximum()) {
147148 std::optional<uint32_t> actualMaximum = table->maximum();
148149 if (!actualMaximum) {
149150 return JSValue::encode(
150  throwException(exec, throwScope, createTypeError(exec, ASCIILiteral("Table import does not have a 'maximum' but the module requires that it does"))));
 151 throwException(exec, throwScope, createWebAssemblyLinkError(exec, ASCIILiteral("Table import does not have a 'maximum' but the module requires that it does"))));
151152 }
152153 if (*actualMaximum > *expectedMaximum) {
153154 return JSValue::encode(
154  throwException(exec, throwScope, createTypeError(exec, ASCIILiteral("Imported Table's 'maximum' is larger than the module's expected 'maximum'"))));
 155 throwException(exec, throwScope, createWebAssemblyLinkError(exec, ASCIILiteral("Imported Table's 'maximum' is larger than the module's expected 'maximum'"))));
155156 }
156157 }
157158

@@static EncodedJSValue JSC_HOST_CALL constructJSWebAssemblyInstance(ExecState* ex
166167 RELEASE_ASSERT(moduleInformation.memory);
167168 hasMemoryImport = true;
168169 JSWebAssemblyMemory* memory = jsDynamicCast<JSWebAssemblyMemory*>(value);
169  // i. If v is not a WebAssembly.Memory object, throw a TypeError.
 170 // i. If v is not a WebAssembly.Memory object, throw a WebAssembly.LinkError.
170171 if (!memory)
171  return JSValue::encode(throwException(exec, throwScope, createTypeError(exec, ASCIILiteral("Memory import is not an instance of WebAssembly.Memory"))));
 172 return JSValue::encode(throwException(exec, throwScope, createWebAssemblyLinkError(exec, ASCIILiteral("Memory import is not an instance of WebAssembly.Memory"))));
172173
173174 Wasm::PageCount expectedInitial = moduleInformation.memory.initial();
174175 Wasm::PageCount actualInitial = memory->memory()->initial();
175176 if (actualInitial < expectedInitial)
176  return JSValue::encode(throwException(exec, throwScope, createTypeError(exec, ASCIILiteral("Memory import provided an 'initial' that is too small"))));
 177 return JSValue::encode(throwException(exec, throwScope, createWebAssemblyLinkError(exec, ASCIILiteral("Memory import provided an 'initial' that is too small"))));
177178
178179 if (Wasm::PageCount expectedMaximum = moduleInformation.memory.maximum()) {
179180 Wasm::PageCount actualMaximum = memory->memory()->maximum();
180181 if (!actualMaximum) {
181182 return JSValue::encode(
182  throwException(exec, throwScope, createTypeError(exec, ASCIILiteral("Memory import did not have a 'maximum' but the module requires that it does"))));
 183 throwException(exec, throwScope, createWebAssemblyLinkError(exec, ASCIILiteral("Memory import did not have a 'maximum' but the module requires that it does"))));
183184 }
184185
185186 if (actualMaximum > expectedMaximum) {
186187 return JSValue::encode(
187  throwException(exec, throwScope, createTypeError(exec, ASCIILiteral("Memory imports 'maximum' is larger than the module's expected 'maximum"))));
 188 throwException(exec, throwScope, createWebAssemblyLinkError(exec, ASCIILiteral("Memory imports 'maximum' is larger than the module's expected 'maximum'"))));
188189 }
189190 }
190191 // ii. Append v to memories.

@@static EncodedJSValue JSC_HOST_CALL constructJSWebAssemblyInstance(ExecState* ex
198199 ASSERT(moduleInformation.globals[import.kindIndex].mutability == Wasm::Global::Immutable);
199200 // ii. If Type(v) is not Number, throw a TypeError.
200201 if (!value.isNumber())
201  return JSValue::encode(throwException(exec, throwScope, createTypeError(exec, ASCIILiteral("imported global must be a number"), defaultSourceAppender, runtimeTypeForValue(value))));
 202 return JSValue::encode(throwException(exec, throwScope, createWebAssemblyLinkError(exec, ASCIILiteral("imported global must be a number"))));
202203 // iii. Append ToWebAssemblyValue(v) to imports.
203204 switch (moduleInformation.globals[import.kindIndex].type) {
204205 case Wasm::I32:

Source/JavaScriptCore/wasm/js/WebAssemblyLinkErrorConstructor.cpp

 1/*
 2 * Copyright (C) 2016 Apple Inc. All rights reserved.
 3 *
 4 * Redistribution and use in source and binary forms, with or without
 5 * modification, are permitted provided that the following conditions
 6 * are met:
 7 * 1. Redistributions of source code must retain the above copyright
 8 * notice, this list of conditions and the following disclaimer.
 9 * 2. Redistributions in binary form must reproduce the above copyright
 10 * notice, this list of conditions and the following disclaimer in the
 11 * documentation and/or other materials provided with the distribution.
 12 *
 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 24 */
 25
 26#include "config.h"
 27#include "WebAssemblyLinkErrorConstructor.h"
 28
 29#if ENABLE(WEBASSEMBLY)
 30
 31#include "FunctionPrototype.h"
 32#include "JSCInlines.h"
 33#include "JSWebAssemblyLinkError.h"
 34#include "WebAssemblyLinkErrorPrototype.h"
 35
 36#include "WebAssemblyLinkErrorConstructor.lut.h"
 37
 38namespace JSC {
 39
 40const ClassInfo WebAssemblyLinkErrorConstructor::s_info = { "Function", &Base::s_info, &constructorTableWebAssemblyLinkError, CREATE_METHOD_TABLE(WebAssemblyLinkErrorConstructor) };
 41
 42/* Source for WebAssemblyLinkErrorConstructor.lut.h
 43 @begin constructorTableWebAssemblyLinkError
 44 @end
 45 */
 46
 47static EncodedJSValue JSC_HOST_CALL constructJSWebAssemblyLinkError(ExecState* state)
 48{
 49 auto& vm = state->vm();
 50 auto scope = DECLARE_THROW_SCOPE(vm);
 51 JSValue message = state->argument(0);
 52 auto* structure = InternalFunction::createSubclassStructure(state, state->newTarget(), asInternalFunction(state->jsCallee())->globalObject()->WebAssemblyLinkErrorStructure());
 53 RETURN_IF_EXCEPTION(scope, { });
 54 return JSValue::encode(JSWebAssemblyLinkError::create(state, structure, message, false));
 55}
 56
 57static EncodedJSValue JSC_HOST_CALL callJSWebAssemblyLinkError(ExecState* state)
 58{
 59 VM& vm = state->vm();
 60 auto scope = DECLARE_THROW_SCOPE(vm);
 61 return JSValue::encode(throwConstructorCannotBeCalledAsFunctionTypeError(state, scope, "WebAssembly.LinkError"));
 62}
 63
 64WebAssemblyLinkErrorConstructor* WebAssemblyLinkErrorConstructor::create(VM& vm, Structure* structure, WebAssemblyLinkErrorPrototype* thisPrototype)
 65{
 66 auto* constructor = new (NotNull, allocateCell<WebAssemblyLinkErrorConstructor>(vm.heap)) WebAssemblyLinkErrorConstructor(vm, structure);
 67 constructor->finishCreation(vm, thisPrototype);
 68 return constructor;
 69}
 70
 71Structure* WebAssemblyLinkErrorConstructor::createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype)
 72{
 73 return Structure::create(vm, globalObject, prototype, TypeInfo(ObjectType, StructureFlags), info());
 74}
 75
 76void WebAssemblyLinkErrorConstructor::finishCreation(VM& vm, WebAssemblyLinkErrorPrototype* prototype)
 77{
 78 Base::finishCreation(vm, ASCIILiteral("LinkError"));
 79 putDirectWithoutTransition(vm, vm.propertyNames->prototype, prototype, ReadOnly | DontEnum | DontDelete);
 80 putDirectWithoutTransition(vm, vm.propertyNames->length, jsNumber(1), ReadOnly | DontEnum | DontDelete);
 81}
 82
 83WebAssemblyLinkErrorConstructor::WebAssemblyLinkErrorConstructor(VM& vm, Structure* structure)
 84 : Base(vm, structure)
 85{
 86}
 87
 88ConstructType WebAssemblyLinkErrorConstructor::getConstructData(JSCell*, ConstructData& constructData)
 89{
 90 constructData.native.function = constructJSWebAssemblyLinkError;
 91 return ConstructType::Host;
 92}
 93
 94CallType WebAssemblyLinkErrorConstructor::getCallData(JSCell*, CallData& callData)
 95{
 96 callData.native.function = callJSWebAssemblyLinkError;
 97 return CallType::Host;
 98}
 99
 100} // namespace JSC
 101
 102#endif // ENABLE(WEBASSEMBLY)

Source/JavaScriptCore/wasm/js/WebAssemblyLinkErrorConstructor.h

 1/*
 2 * Copyright (C) 2016 Apple Inc. All rights reserved.
 3 *
 4 * Redistribution and use in source and binary forms, with or without
 5 * modification, are permitted provided that the following conditions
 6 * are met:
 7 * 1. Redistributions of source code must retain the above copyright
 8 * notice, this list of conditions and the following disclaimer.
 9 * 2. Redistributions in binary form must reproduce the above copyright
 10 * notice, this list of conditions and the following disclaimer in the
 11 * documentation and/or other materials provided with the distribution.
 12 *
 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 24 */
 25
 26#pragma once
 27
 28#if ENABLE(WEBASSEMBLY)
 29
 30#include "InternalFunction.h"
 31#include "JSObject.h"
 32
 33namespace JSC {
 34
 35class WebAssemblyLinkErrorPrototype;
 36
 37class WebAssemblyLinkErrorConstructor : public InternalFunction {
 38public:
 39 typedef InternalFunction Base;
 40 static const unsigned StructureFlags = Base::StructureFlags | HasStaticPropertyTable;
 41
 42 static WebAssemblyLinkErrorConstructor* create(VM&, Structure*, WebAssemblyLinkErrorPrototype*);
 43 static Structure* createStructure(VM&, JSGlobalObject*, JSValue);
 44
 45 DECLARE_INFO;
 46
 47protected:
 48 void finishCreation(VM&, WebAssemblyLinkErrorPrototype*);
 49
 50private:
 51 WebAssemblyLinkErrorConstructor(VM&, Structure*);
 52 static ConstructType getConstructData(JSCell*, ConstructData&);
 53 static CallType getCallData(JSCell*, CallData&);
 54};
 55
 56} // namespace JSC
 57
 58#endif // ENABLE(WEBASSEMBLY)

Source/JavaScriptCore/wasm/js/WebAssemblyLinkErrorPrototype.cpp

 1/*
 2 * Copyright (C) 2016 Apple Inc. All rights reserved.
 3 *
 4 * Redistribution and use in source and binary forms, with or without
 5 * modification, are permitted provided that the following conditions
 6 * are met:
 7 * 1. Redistributions of source code must retain the above copyright
 8 * notice, this list of conditions and the following disclaimer.
 9 * 2. Redistributions in binary form must reproduce the above copyright
 10 * notice, this list of conditions and the following disclaimer in the
 11 * documentation and/or other materials provided with the distribution.
 12 *
 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 24 */
 25
 26#include "config.h"
 27#include "WebAssemblyLinkErrorPrototype.h"
 28
 29#if ENABLE(WEBASSEMBLY)
 30
 31#include "FunctionPrototype.h"
 32#include "JSCInlines.h"
 33
 34#include "WebAssemblyLinkErrorPrototype.lut.h"
 35
 36namespace JSC {
 37
 38const ClassInfo WebAssemblyLinkErrorPrototype::s_info = { "WebAssembly.LinkError.prototype", &Base::s_info, &prototypeTableWebAssemblyLinkError, CREATE_METHOD_TABLE(WebAssemblyLinkErrorPrototype) };
 39
 40/* Source for WebAssemblyLinkErrorPrototype.lut.h
 41 @begin prototypeTableWebAssemblyLinkError
 42 @end
 43 */
 44
 45WebAssemblyLinkErrorPrototype* WebAssemblyLinkErrorPrototype::create(VM& vm, JSGlobalObject*, Structure* structure)
 46{
 47 auto* object = new (NotNull, allocateCell<WebAssemblyLinkErrorPrototype>(vm.heap)) WebAssemblyLinkErrorPrototype(vm, structure);
 48 object->finishCreation(vm);
 49 return object;
 50}
 51
 52Structure* WebAssemblyLinkErrorPrototype::createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype)
 53{
 54 return Structure::create(vm, globalObject, prototype, TypeInfo(ObjectType, StructureFlags), info());
 55}
 56
 57void WebAssemblyLinkErrorPrototype::finishCreation(VM& vm)
 58{
 59 Base::finishCreation(vm);
 60}
 61
 62WebAssemblyLinkErrorPrototype::WebAssemblyLinkErrorPrototype(VM& vm, Structure* structure)
 63 : Base(vm, structure)
 64{
 65}
 66
 67} // namespace JSC
 68
 69#endif // ENABLE(WEBASSEMBLY)

Source/JavaScriptCore/wasm/js/WebAssemblyLinkErrorPrototype.h

 1/*
 2 * Copyright (C) 2016 Apple Inc. All rights reserved.
 3 *
 4 * Redistribution and use in source and binary forms, with or without
 5 * modification, are permitted provided that the following conditions
 6 * are met:
 7 * 1. Redistributions of source code must retain the above copyright
 8 * notice, this list of conditions and the following disclaimer.
 9 * 2. Redistributions in binary form must reproduce the above copyright
 10 * notice, this list of conditions and the following disclaimer in the
 11 * documentation and/or other materials provided with the distribution.
 12 *
 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 24 */
 25
 26#pragma once
 27
 28#if ENABLE(WEBASSEMBLY)
 29
 30#include "JSDestructibleObject.h"
 31#include "JSObject.h"
 32
 33namespace JSC {
 34
 35class WebAssemblyLinkErrorPrototype : public JSNonFinalObject {
 36public:
 37 typedef JSNonFinalObject Base;
 38 static const unsigned StructureFlags = Base::StructureFlags | HasStaticPropertyTable;
 39
 40 static WebAssemblyLinkErrorPrototype* create(VM&, JSGlobalObject*, Structure*);
 41 static Structure* createStructure(VM&, JSGlobalObject*, JSValue);
 42
 43 DECLARE_INFO;
 44
 45protected:
 46 void finishCreation(VM&);
 47
 48private:
 49 WebAssemblyLinkErrorPrototype(VM&, Structure*);
 50};
 51
 52} // namespace JSC
 53
 54#endif // ENABLE(WEBASSEMBLY)

Source/JavaScriptCore/wasm/js/WebAssemblyModuleRecord.cpp

3333#include "JSLexicalEnvironment.h"
3434#include "JSModuleEnvironment.h"
3535#include "JSWebAssemblyInstance.h"
 36#include "JSWebAssemblyLinkError.h"
3637#include "JSWebAssemblyModule.h"
3738#include "ProtoCallFrame.h"
3839#include "WasmFormat.h"

@@void WebAssemblyModuleRecord::link(ExecState* state, JSWebAssemblyInstance* inst
197198template <typename Scope, typename N, typename ...Args>
198199NEVER_INLINE static JSValue dataSegmentFail(ExecState* state, Scope& scope, N memorySize, N segmentSize, N offset, Args... args)
199200{
200  return throwException(state, scope, createRangeError(state, makeString(ASCIILiteral("Invalid data segment initialization: segment of "), String::number(segmentSize), ASCIILiteral(" bytes memory of "), String::number(memorySize), ASCIILiteral(" bytes, at offset "), String::number(offset), args...)));
 201 return throwException(state, scope, createWebAssemblyLinkError(state, makeString(ASCIILiteral("Invalid data segment initialization: segment of "), String::number(segmentSize), ASCIILiteral(" bytes memory of "), String::number(memorySize), ASCIILiteral(" bytes, at offset "), String::number(offset), args...)));
201202}
202203
203204JSValue WebAssemblyModuleRecord::evaluate(ExecState* state)

@@JSValue WebAssemblyModuleRecord::evaluate(ExecState* state)
221222 uint32_t tableIndex = element.offset;
222223 uint64_t lastWrittenIndex = static_cast<uint64_t>(tableIndex) + static_cast<uint64_t>(element.functionIndices.size()) - 1;
223224 if (lastWrittenIndex >= table->size())
224  return JSValue::decode(throwVMRangeError(state, scope, ASCIILiteral("Element is trying to set an out of bounds table index")));
 225 return throwException(state, scope, createWebAssemblyLinkError(state, ASCIILiteral("Element is trying to set an out of bounds table index")));
225226
226227 for (uint32_t i = 0; i < element.functionIndices.size(); ++i) {
227228 // FIXME: This essentially means we're exporting an import.