Changeset 189846 in webkit
- Timestamp:
- Sep 15, 2015 10:49:11 PM (9 years ago)
- Location:
- trunk/Source/JavaScriptCore
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/ChangeLog
r189844 r189846 1 2015-09-15 Sukolsak Sakshuwong <sukolsak@gmail.com> 2 3 Implement imported global variables in WebAssembly 4 https://bugs.webkit.org/show_bug.cgi?id=149206 5 6 Reviewed by Filip Pizlo. 7 8 Values can now be imported to a WebAssembly module through properties of 9 the imports object that is passed to loadWebAssembly(). In order to 10 avoid any side effect when accessing the imports object, we check that 11 the properties are data properties. We also check that each value is a 12 primitive and is not a Symbol. According to the ECMA262 6.0 spec, 13 calling ToNumber() on a primitive that is not a Symbol should not cause 14 any side effect.[1] 15 16 [1]: http://www.ecma-international.org/ecma-262/6.0/#sec-tonumber 17 18 * tests/stress/wasm-globals.js: 19 * tests/stress/wasm/globals.wasm: 20 * wasm/WASMModuleParser.cpp: 21 (JSC::WASMModuleParser::parseModule): 22 (JSC::WASMModuleParser::parseGlobalSection): 23 * wasm/WASMModuleParser.h: 24 1 25 2015-09-15 Sukolsak Sakshuwong <sukolsak@gmail.com> 2 26 -
trunk/Source/JavaScriptCore/tests/stress/wasm-globals.js
r189844 r189846 9 9 wasm/globals.wasm is generated by pack-asmjs <https://github.com/WebAssembly/polyfill-prototype-1> from the following script: 10 10 11 function asmModule(global, env, buffer) {11 function asmModule(global, imports, buffer) { 12 12 "use asm"; 13 13 14 14 var fround = global.Math.fround; 15 var a = imports.a | 0; 16 var b = fround(imports.b); 17 var c = +imports.c; 15 18 var x = 0; 16 19 var y = fround(0); 17 20 var z = 0.0; 21 22 function getA() { 23 return a | 0; 24 } 25 26 function getB() { 27 return b; 28 } 29 30 function getC() { 31 return c; 32 } 18 33 19 34 function getX() { … … 45 60 46 61 return { 62 getA: getA, 63 getB: getB, 64 getC: getC, 47 65 getX: getX, 48 66 getY: getY, … … 55 73 */ 56 74 57 var module = loadWebAssembly("wasm/globals.wasm"); 75 var imports = { 76 a: 42, 77 b: 4.2, 78 c: 4.2, 79 }; 80 var module = loadWebAssembly("wasm/globals.wasm", imports); 81 82 shouldBe(module.getA(), 42); 83 shouldBe(module.getB(), 4.199999809265137); 84 shouldBe(module.getC(), 4.2); 58 85 59 86 shouldBe(module.getX(), 0); -
trunk/Source/JavaScriptCore/wasm/WASMModuleParser.cpp
r189822 r189846 85 85 parseFunctionImportSection(exec); 86 86 PROPAGATE_ERROR(); 87 parseGlobalSection( );87 parseGlobalSection(exec); 88 88 PROPAGATE_ERROR(); 89 89 parseFunctionDeclarationSection(); … … 182 182 } 183 183 184 void WASMModuleParser::parseGlobalSection( )184 void WASMModuleParser::parseGlobalSection(ExecState* exec) 185 185 { 186 186 uint32_t numberOfInternalI32GlobalVariables; … … 219 219 READ_STRING_OR_FAIL(importName, "Cannot read the import name of an int32 global variable."); 220 220 globalVariableTypes.uncheckedAppend(WASMType::I32); 221 globalVariables.uncheckedAppend(JSWASMModule::GlobalVariable(0)); // FIXME: Import the value. 221 JSValue value; 222 getImportedValue(exec, importName, value); 223 PROPAGATE_ERROR(); 224 FAIL_IF_FALSE(value.isPrimitive() && !value.isSymbol(), "\"" + importName + "\" is not a primitive or is a Symbol."); 225 globalVariables.uncheckedAppend(JSWASMModule::GlobalVariable(value.toInt32(exec))); 222 226 } 223 227 for (uint32_t i = 0; i < numberOfImportedF32GlobalVariables; ++i) { … … 225 229 READ_STRING_OR_FAIL(importName, "Cannot read the import name of a float32 global variable."); 226 230 globalVariableTypes.uncheckedAppend(WASMType::F32); 227 globalVariables.uncheckedAppend(JSWASMModule::GlobalVariable(0.0f)); // FIXME: Import the value. 231 JSValue value; 232 getImportedValue(exec, importName, value); 233 PROPAGATE_ERROR(); 234 FAIL_IF_FALSE(value.isPrimitive() && !value.isSymbol(), "\"" + importName + "\" is not a primitive or is a Symbol."); 235 globalVariables.uncheckedAppend(JSWASMModule::GlobalVariable(static_cast<float>(value.toNumber(exec)))); 228 236 } 229 237 for (uint32_t i = 0; i < numberOfImportedF64GlobalVariables; ++i) { … … 231 239 READ_STRING_OR_FAIL(importName, "Cannot read the import name of a float64 global variable."); 232 240 globalVariableTypes.uncheckedAppend(WASMType::F64); 233 globalVariables.uncheckedAppend(JSWASMModule::GlobalVariable(0.0)); // FIXME: Import the value. 241 JSValue value; 242 getImportedValue(exec, importName, value); 243 PROPAGATE_ERROR(); 244 FAIL_IF_FALSE(value.isPrimitive() && !value.isSymbol(), "\"" + importName + "\" is not a primitive or is a Symbol."); 245 globalVariables.uncheckedAppend(JSWASMModule::GlobalVariable(value.toNumber(exec))); 234 246 } 235 247 } -
trunk/Source/JavaScriptCore/wasm/WASMModuleParser.h
r189822 r189846 51 51 void parseSignatureSection(); 52 52 void parseFunctionImportSection(ExecState*); 53 void parseGlobalSection( );53 void parseGlobalSection(ExecState*); 54 54 void parseFunctionDeclarationSection(); 55 55 void parseFunctionPointerTableSection();
Note: See TracChangeset
for help on using the changeset viewer.