Changeset 215664 in webkit
- Timestamp:
- Apr 22, 2017 12:52:03 AM (7 years ago)
- Location:
- trunk
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JSTests/ChangeLog
r215662 r215664 1 2017-04-22 JF Bastien <jfbastien@apple.com> 2 3 WebAssembly: Module.exports, Module.imports, Module.customSections are wrong 4 https://bugs.webkit.org/show_bug.cgi?id=171078 5 6 Reviewed by Saam Barati. 7 8 They're static properties of Module, not instance properties of a module. 9 https://github.com/WebAssembly/design/blob/master/JS.md#webassemblymoduleexports 10 11 * wasm/js-api/Module.customSection.js: 12 (assert.throws.WebAssembly.Module.customSections): 13 (assert.eq): 14 (assert.throws.WebAssembly.Module.prototype.customSections): Deleted. 15 * wasm/js-api/Module.exports.js: 16 (assert.throws.WebAssembly.Module.exports): 17 (assert.truthy): 18 (assert.throws.WebAssembly.Module.prototype.exports): Deleted. 19 * wasm/js-api/Module.imports.js: 20 (assert.throws.WebAssembly.Module.imports): 21 (assert.truthy): 22 (assert.throws.WebAssembly.Module.prototype.imports): Deleted. 23 1 24 2017-04-21 JF Bastien <jfbastien@apple.com> 2 25 -
trunk/JSTests/wasm/js-api/Module.customSection.js
r210282 r215664 2 2 import * as assert from '../assert.js'; 3 3 4 assert.throws(() => WebAssembly.Module.prototype.customSections(undefined, ""), TypeError, `WebAssembly.Module.prototype.customSections called with non WebAssembly.Module |this| value`); 4 assert.throws(() => WebAssembly.Module.customSections(undefined, ""), TypeError, `WebAssembly.Module.customSections called with non WebAssembly.Module argument`); 5 assert.eq(WebAssembly.Module.customSections.length, 2); 5 6 6 7 { 7 8 const empty = new WebAssembly.Module((new Builder()).WebAssembly().get()); 8 assert.isArray( empty.customSections(""));9 assert.eq( empty.customSections("").length, 0);9 assert.isArray(WebAssembly.Module.customSections(empty, "")); 10 assert.eq(WebAssembly.Module.customSections(empty, "").length, 0); 10 11 } 11 12 … … 14 15 .Unknown("hello").Byte(0x00).Byte(0x42).Byte(0xFF).End() 15 16 .WebAssembly().get()); 16 assert.eq( single.customSections("").length, 0);17 const hello = single.customSections("hello");17 assert.eq(WebAssembly.Module.customSections(single, "").length, 0); 18 const hello = WebAssembly.Module.customSections(single, "hello"); 18 19 assert.eq(hello.length, 1); 19 20 assert.eq(hello[0].byteLength, 3); … … 28 29 .Unknown("👨❤️💋👨").Byte(42).End() 29 30 .WebAssembly().get()); 30 const family = unicode.customSections("👨❤️💋👨");31 const family = WebAssembly.Module.customSections(unicode, "👨❤️💋👨"); 31 32 assert.eq(family.length, 1); 32 33 assert.eq(family[0].byteLength, 1); … … 44 45 .WebAssembly().get()); 45 46 46 const zero = many.customSections("zero");47 const zero = WebAssembly.Module.customSections(many, "zero"); 47 48 assert.eq(zero.length, 1); 48 49 assert.eq(zero[0].byteLength, 1); … … 50 51 assert.eq(zeroI8[0], 0); 51 52 52 const two = many.customSections("two");53 const two = WebAssembly.Module.customSections(many, "two"); 53 54 assert.eq(two.length, 1); 54 55 assert.eq(two[0].byteLength, 4); … … 59 60 assert.eq(twoI8[3], 3); 60 61 61 const one = many.customSections("one");62 const one = WebAssembly.Module.customSections(many, "one"); 62 63 assert.eq(one.length, 3); 63 64 let seen = 0; -
trunk/JSTests/wasm/js-api/Module.exports.js
r214484 r215664 2 2 import * as assert from '../assert.js'; 3 3 4 assert.throws(() => WebAssembly.Module.prototype.exports(undefined, ""), TypeError, `WebAssembly.Module.prototype.exports called with non WebAssembly.Module |this| value`); 4 assert.throws(() => WebAssembly.Module.exports(undefined), TypeError, `WebAssembly.Module.exports called with non WebAssembly.Module argument`); 5 assert.eq(WebAssembly.Module.exports.length, 1); 5 6 6 7 { 7 8 const m = new WebAssembly.Module((new Builder()).WebAssembly().get()); 8 assert.isArray( m.exports);9 assert.eq( m.exports.length, 0);10 assert.truthy( m.exports !== m.exports);9 assert.isArray(WebAssembly.Module.exports(m)); 10 assert.eq(WebAssembly.Module.exports(m).length, 0); 11 assert.truthy(WebAssembly.Module.exports(m) !== WebAssembly.Module.exports(m)); 11 12 } 12 13 … … 31 32 .End() 32 33 .WebAssembly().get()); 33 assert.eq( m.exports.length, 4);34 assert.eq( m.exports[0].name, "func");35 assert.eq( m.exports[0].kind, "function");36 assert.eq( m.exports[1].name, "tab");37 assert.eq( m.exports[1].kind, "table");38 assert.eq( m.exports[2].name, "mem");39 assert.eq( m.exports[2].kind, "memory");40 assert.eq( m.exports[3].name, "glob");41 assert.eq( m.exports[3].kind, "global");34 assert.eq(WebAssembly.Module.exports(m).length, 4); 35 assert.eq(WebAssembly.Module.exports(m)[0].name, "func"); 36 assert.eq(WebAssembly.Module.exports(m)[0].kind, "function"); 37 assert.eq(WebAssembly.Module.exports(m)[1].name, "tab"); 38 assert.eq(WebAssembly.Module.exports(m)[1].kind, "table"); 39 assert.eq(WebAssembly.Module.exports(m)[2].name, "mem"); 40 assert.eq(WebAssembly.Module.exports(m)[2].kind, "memory"); 41 assert.eq(WebAssembly.Module.exports(m)[3].name, "glob"); 42 assert.eq(WebAssembly.Module.exports(m)[3].kind, "global"); 42 43 } -
trunk/JSTests/wasm/js-api/Module.imports.js
r214484 r215664 2 2 import * as assert from '../assert.js'; 3 3 4 assert.throws(() => WebAssembly.Module.prototype.imports(undefined, ""), TypeError, `WebAssembly.Module.prototype.imports called with non WebAssembly.Module |this| value`); 4 assert.throws(() => WebAssembly.Module.imports(undefined), TypeError, `WebAssembly.Module.imports called with non WebAssembly.Module argument`); 5 assert.eq(WebAssembly.Module.imports.length, 1); 5 6 6 7 { 7 8 const m = new WebAssembly.Module((new Builder()).WebAssembly().get()); 8 assert.isArray( m.imports);9 assert.eq( m.imports.length, 0);10 assert.truthy( m.exports !== m.exports);9 assert.isArray(WebAssembly.Module.imports(m)); 10 assert.eq(WebAssembly.Module.imports(m).length, 0); 11 assert.truthy(WebAssembly.Module.imports(m) !== WebAssembly.Module.imports(m)); 11 12 } 12 13 … … 22 23 .End() 23 24 .WebAssembly().get()); 24 assert.eq( m.imports.length, 4);25 assert.eq( m.imports[0].module, "fooFunction");26 assert.eq( m.imports[0].name, "barFunction");27 assert.eq( m.imports[0].kind, "function");28 assert.eq( m.imports[1].module, "fooTable");29 assert.eq( m.imports[1].name, "barTable");30 assert.eq( m.imports[1].kind, "table");31 assert.eq( m.imports[2].module, "fooMemory");32 assert.eq( m.imports[2].name, "barMemory");33 assert.eq( m.imports[2].kind, "memory");34 assert.eq( m.imports[3].module, "fooGlobal");35 assert.eq( m.imports[3].name, "barGlobal");36 assert.eq( m.imports[3].kind, "global");25 assert.eq(WebAssembly.Module.imports(m).length, 4); 26 assert.eq(WebAssembly.Module.imports(m)[0].module, "fooFunction"); 27 assert.eq(WebAssembly.Module.imports(m)[0].name, "barFunction"); 28 assert.eq(WebAssembly.Module.imports(m)[0].kind, "function"); 29 assert.eq(WebAssembly.Module.imports(m)[1].module, "fooTable"); 30 assert.eq(WebAssembly.Module.imports(m)[1].name, "barTable"); 31 assert.eq(WebAssembly.Module.imports(m)[1].kind, "table"); 32 assert.eq(WebAssembly.Module.imports(m)[2].module, "fooMemory"); 33 assert.eq(WebAssembly.Module.imports(m)[2].name, "barMemory"); 34 assert.eq(WebAssembly.Module.imports(m)[2].kind, "memory"); 35 assert.eq(WebAssembly.Module.imports(m)[3].module, "fooGlobal"); 36 assert.eq(WebAssembly.Module.imports(m)[3].name, "barGlobal"); 37 assert.eq(WebAssembly.Module.imports(m)[3].kind, "global"); 37 38 } -
trunk/Source/JavaScriptCore/ChangeLog
r215644 r215664 1 2017-04-22 JF Bastien <jfbastien@apple.com> 2 3 WebAssembly: Module.exports, Module.imports, Module.customSections are wrong 4 https://bugs.webkit.org/show_bug.cgi?id=171078 5 6 Reviewed by Saam Barati. 7 8 They're static properties of Module, not instance properties of a module. 9 https://github.com/WebAssembly/design/blob/master/JS.md#webassemblymoduleexports 10 11 * wasm/js/WebAssemblyModuleConstructor.cpp: 12 (JSC::webAssemblyModuleCustomSections): 13 (JSC::webAssemblyModuleImports): 14 (JSC::webAssemblyModuleExports): 15 * wasm/js/WebAssemblyModulePrototype.cpp: 16 (JSC::webAssemblyModuleProtoCustomSections): Deleted. 17 (JSC::webAssemblyModuleProtoImports): Deleted. 18 (JSC::webAssemblyModuleProtoExports): Deleted. 19 1 20 2017-04-21 Saam Barati <sbarati@apple.com> 2 21 -
trunk/Source/JavaScriptCore/wasm/js/WebAssemblyModuleConstructor.cpp
r215103 r215664 1 1 /* 2 * Copyright (C) 2016 Apple Inc. All rights reserved.2 * Copyright (C) 2016-2017 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 29 29 #if ENABLE(WEBASSEMBLY) 30 30 31 #include "ArrayBuffer.h" 31 32 #include "ExceptionHelpers.h" 32 33 #include "FunctionPrototype.h" … … 37 38 #include "JSWebAssemblyHelpers.h" 38 39 #include "JSWebAssemblyModule.h" 40 #include "ObjectConstructor.h" 39 41 #include "SymbolTable.h" 40 42 #include "WasmCallee.h" 43 #include "WasmModuleInformation.h" 41 44 #include "WasmPlan.h" 42 45 #include "WebAssemblyModulePrototype.h" 43 46 #include <wtf/StdLibExtras.h> 44 47 48 namespace JSC { 49 static EncodedJSValue JSC_HOST_CALL webAssemblyModuleCustomSections(ExecState*); 50 static EncodedJSValue JSC_HOST_CALL webAssemblyModuleImports(ExecState*); 51 static EncodedJSValue JSC_HOST_CALL webAssemblyModuleExports(ExecState*); 52 } 53 45 54 #include "WebAssemblyModuleConstructor.lut.h" 46 55 … … 51 60 /* Source for WebAssemblyModuleConstructor.lut.h 52 61 @begin constructorTableWebAssemblyModule 62 customSections webAssemblyModuleCustomSections DontEnum|Function 2 63 imports webAssemblyModuleImports DontEnum|Function 1 64 exports webAssemblyModuleExports DontEnum|Function 1 53 65 @end 54 66 */ 67 68 EncodedJSValue JSC_HOST_CALL webAssemblyModuleCustomSections(ExecState* exec) 69 { 70 VM& vm = exec->vm(); 71 auto* globalObject = exec->lexicalGlobalObject(); 72 auto throwScope = DECLARE_THROW_SCOPE(vm); 73 74 JSWebAssemblyModule* module = jsDynamicCast<JSWebAssemblyModule*>(vm, exec->argument(0)); 75 if (!module) 76 return JSValue::encode(throwException(exec, throwScope, createTypeError(exec, ASCIILiteral("WebAssembly.Module.customSections called with non WebAssembly.Module argument")))); 77 78 const String sectionNameString = exec->argument(1).getString(exec); 79 RETURN_IF_EXCEPTION(throwScope, { }); 80 81 JSArray* result = constructEmptyArray(exec, nullptr, globalObject); 82 RETURN_IF_EXCEPTION(throwScope, { }); 83 84 const auto& customSections = module->moduleInformation().customSections; 85 for (const Wasm::CustomSection& section : customSections) { 86 if (String::fromUTF8(section.name) == sectionNameString) { 87 auto buffer = ArrayBuffer::tryCreate(section.payload.data(), section.payload.size()); 88 if (!buffer) 89 return JSValue::encode(throwException(exec, throwScope, createOutOfMemoryError(exec))); 90 91 result->push(exec, JSArrayBuffer::create(vm, globalObject->m_arrayBufferStructure.get(), WTFMove(buffer))); 92 RETURN_IF_EXCEPTION(throwScope, { }); 93 } 94 } 95 96 return JSValue::encode(result); 97 } 98 99 EncodedJSValue JSC_HOST_CALL webAssemblyModuleImports(ExecState* exec) 100 { 101 VM& vm = exec->vm(); 102 auto* globalObject = exec->lexicalGlobalObject(); 103 auto throwScope = DECLARE_THROW_SCOPE(vm); 104 105 JSWebAssemblyModule* module = jsDynamicCast<JSWebAssemblyModule*>(vm, exec->argument(0)); 106 if (!module) 107 return JSValue::encode(throwException(exec, throwScope, createTypeError(exec, ASCIILiteral("WebAssembly.Module.imports called with non WebAssembly.Module argument")))); 108 109 JSArray* result = constructEmptyArray(exec, nullptr, globalObject); 110 RETURN_IF_EXCEPTION(throwScope, { }); 111 112 const auto& imports = module->moduleInformation().imports; 113 if (imports.size()) { 114 Identifier module = Identifier::fromString(exec, "module"); 115 Identifier name = Identifier::fromString(exec, "name"); 116 Identifier kind = Identifier::fromString(exec, "kind"); 117 for (const Wasm::Import& imp : imports) { 118 JSObject* obj = constructEmptyObject(exec); 119 RETURN_IF_EXCEPTION(throwScope, { }); 120 obj->putDirect(vm, module, jsString(exec, String::fromUTF8(imp.module))); 121 obj->putDirect(vm, name, jsString(exec, String::fromUTF8(imp.field))); 122 obj->putDirect(vm, kind, jsString(exec, String(makeString(imp.kind)))); 123 result->push(exec, obj); 124 RETURN_IF_EXCEPTION(throwScope, { }); 125 } 126 } 127 128 return JSValue::encode(result); 129 } 130 131 EncodedJSValue JSC_HOST_CALL webAssemblyModuleExports(ExecState* exec) 132 { 133 VM& vm = exec->vm(); 134 auto* globalObject = exec->lexicalGlobalObject(); 135 auto throwScope = DECLARE_THROW_SCOPE(vm); 136 137 JSWebAssemblyModule* module = jsDynamicCast<JSWebAssemblyModule*>(vm, exec->argument(0)); 138 if (!module) 139 return JSValue::encode(throwException(exec, throwScope, createTypeError(exec, ASCIILiteral("WebAssembly.Module.exports called with non WebAssembly.Module argument")))); 140 141 JSArray* result = constructEmptyArray(exec, nullptr, globalObject); 142 RETURN_IF_EXCEPTION(throwScope, { }); 143 144 const auto& exports = module->moduleInformation().exports; 145 if (exports.size()) { 146 Identifier name = Identifier::fromString(exec, "name"); 147 Identifier kind = Identifier::fromString(exec, "kind"); 148 for (const Wasm::Export& exp : exports) { 149 JSObject* obj = constructEmptyObject(exec); 150 RETURN_IF_EXCEPTION(throwScope, { }); 151 obj->putDirect(vm, name, jsString(exec, String::fromUTF8(exp.field))); 152 obj->putDirect(vm, kind, jsString(exec, String(makeString(exp.kind)))); 153 result->push(exec, obj); 154 RETURN_IF_EXCEPTION(throwScope, { }); 155 } 156 } 157 158 return JSValue::encode(result); 159 } 55 160 56 161 static EncodedJSValue JSC_HOST_CALL constructJSWebAssemblyModule(ExecState* exec) -
trunk/Source/JavaScriptCore/wasm/js/WebAssemblyModulePrototype.cpp
r215353 r215664 29 29 #if ENABLE(WEBASSEMBLY) 30 30 31 #include "ArrayBuffer.h"32 #include "FunctionPrototype.h"33 #include "JSArrayBuffer.h"34 31 #include "JSCInlines.h" 35 #include "JSWebAssemblyModule.h"36 #include "ObjectConstructor.h"37 #include "WasmModuleInformation.h"38 39 namespace JSC {40 static EncodedJSValue JSC_HOST_CALL webAssemblyModuleProtoCustomSections(ExecState*);41 static EncodedJSValue JSC_HOST_CALL webAssemblyModuleProtoImports(ExecState*);42 static EncodedJSValue JSC_HOST_CALL webAssemblyModuleProtoExports(ExecState*);43 }44 32 45 33 #include "WebAssemblyModulePrototype.lut.h" … … 51 39 /* Source for WebAssemblyModulePrototype.lut.h 52 40 @begin prototypeTableWebAssemblyModule 53 customSections webAssemblyModuleProtoCustomSections DontEnum|Function 154 imports webAssemblyModuleProtoImports DontEnum|Accessor 055 exports webAssemblyModuleProtoExports DontEnum|Accessor 056 41 @end 57 42 */ 58 59 EncodedJSValue JSC_HOST_CALL webAssemblyModuleProtoCustomSections(ExecState* exec)60 {61 VM& vm = exec->vm();62 auto* globalObject = exec->lexicalGlobalObject();63 auto throwScope = DECLARE_THROW_SCOPE(vm);64 65 JSWebAssemblyModule* module = jsDynamicCast<JSWebAssemblyModule*>(vm, exec->thisValue());66 if (!module)67 return JSValue::encode(throwException(exec, throwScope, createTypeError(exec, ASCIILiteral("WebAssembly.Module.prototype.customSections called with non WebAssembly.Module |this| value"))));68 69 const String sectionNameString = exec->argument(0).getString(exec);70 RETURN_IF_EXCEPTION(throwScope, { });71 72 JSArray* result = constructEmptyArray(exec, nullptr, globalObject);73 RETURN_IF_EXCEPTION(throwScope, { });74 75 const auto& customSections = module->moduleInformation().customSections;76 for (const Wasm::CustomSection& section : customSections) {77 if (String::fromUTF8(section.name) == sectionNameString) {78 auto buffer = ArrayBuffer::tryCreate(section.payload.data(), section.payload.size());79 if (!buffer)80 return JSValue::encode(throwException(exec, throwScope, createOutOfMemoryError(exec)));81 82 Structure* arrayBufferStructure = InternalFunction::createSubclassStructure(exec, JSValue(), globalObject->arrayBufferStructure(ArrayBufferSharingMode::Default));83 RETURN_IF_EXCEPTION(throwScope, { });84 85 result->push(exec, JSArrayBuffer::create(vm, arrayBufferStructure, WTFMove(buffer)));86 RETURN_IF_EXCEPTION(throwScope, { });87 }88 }89 90 return JSValue::encode(result);91 }92 93 EncodedJSValue JSC_HOST_CALL webAssemblyModuleProtoImports(ExecState* exec)94 {95 VM& vm = exec->vm();96 auto* globalObject = exec->lexicalGlobalObject();97 auto throwScope = DECLARE_THROW_SCOPE(vm);98 99 JSWebAssemblyModule* module = jsDynamicCast<JSWebAssemblyModule*>(vm, exec->thisValue());100 if (!module)101 return JSValue::encode(throwException(exec, throwScope, createTypeError(exec, ASCIILiteral("WebAssembly.Module.prototype.imports called with non WebAssembly.Module |this| value"))));102 103 JSArray* result = constructEmptyArray(exec, nullptr, globalObject);104 RETURN_IF_EXCEPTION(throwScope, { });105 106 const auto& imports = module->moduleInformation().imports;107 if (imports.size()) {108 Identifier module = Identifier::fromString(exec, "module");109 Identifier name = Identifier::fromString(exec, "name");110 Identifier kind = Identifier::fromString(exec, "kind");111 for (const Wasm::Import& imp : imports) {112 JSObject* obj = constructEmptyObject(exec);113 RETURN_IF_EXCEPTION(throwScope, { });114 obj->putDirect(vm, module, jsString(exec, String::fromUTF8(imp.module)));115 obj->putDirect(vm, name, jsString(exec, String::fromUTF8(imp.field)));116 obj->putDirect(vm, kind, jsString(exec, String(makeString(imp.kind))));117 result->push(exec, obj);118 RETURN_IF_EXCEPTION(throwScope, { });119 }120 }121 122 return JSValue::encode(result);123 }124 125 EncodedJSValue JSC_HOST_CALL webAssemblyModuleProtoExports(ExecState* exec)126 {127 VM& vm = exec->vm();128 auto* globalObject = exec->lexicalGlobalObject();129 auto throwScope = DECLARE_THROW_SCOPE(vm);130 131 JSWebAssemblyModule* module = jsDynamicCast<JSWebAssemblyModule*>(vm, exec->thisValue());132 if (!module)133 return JSValue::encode(throwException(exec, throwScope, createTypeError(exec, ASCIILiteral("WebAssembly.Module.prototype.exports called with non WebAssembly.Module |this| value"))));134 135 JSArray* result = constructEmptyArray(exec, nullptr, globalObject);136 RETURN_IF_EXCEPTION(throwScope, { });137 138 const auto& exports = module->moduleInformation().exports;139 if (exports.size()) {140 Identifier name = Identifier::fromString(exec, "name");141 Identifier kind = Identifier::fromString(exec, "kind");142 for (const Wasm::Export& exp : exports) {143 JSObject* obj = constructEmptyObject(exec);144 RETURN_IF_EXCEPTION(throwScope, { });145 obj->putDirect(vm, name, jsString(exec, String::fromUTF8(exp.field)));146 obj->putDirect(vm, kind, jsString(exec, String(makeString(exp.kind))));147 result->push(exec, obj);148 RETURN_IF_EXCEPTION(throwScope, { });149 }150 }151 152 return JSValue::encode(result);153 }154 43 155 44 WebAssemblyModulePrototype* WebAssemblyModulePrototype::create(VM& vm, JSGlobalObject*, Structure* structure)
Note: See TracChangeset
for help on using the changeset viewer.