WebAssembly: construct 32-bit encodedJSValue properly
authorjfbastien@apple.com <jfbastien@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 20 Dec 2016 22:16:28 +0000 (22:16 +0000)
committerjfbastien@apple.com <jfbastien@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 20 Dec 2016 22:16:28 +0000 (22:16 +0000)
https://bugs.webkit.org/show_bug.cgi?id=166199

Reviewed by Mark Lam.

Constructing an encodedJSValue using `{ }` yields the wrong value
on 32-bit platforms. WebAssembly doesn't currently target 32-bit
platforms, but we may as well get it right.

* wasm/JSWebAssembly.cpp:
(JSC::webAssemblyCompileFunc):
(JSC::webAssemblyValidateFunc):
* wasm/js/JSWebAssemblyHelpers.h:
(JSC::toNonWrappingUint32):
* wasm/js/WebAssemblyCompileErrorConstructor.cpp:
(JSC::constructJSWebAssemblyCompileError):
* wasm/js/WebAssemblyFunction.cpp:
(JSC::callWebAssemblyFunction):
* wasm/js/WebAssemblyInstanceConstructor.cpp:
(JSC::constructJSWebAssemblyInstance):
* wasm/js/WebAssemblyMemoryConstructor.cpp:
(JSC::constructJSWebAssemblyMemory):
* wasm/js/WebAssemblyModuleConstructor.cpp:
(JSC::constructJSWebAssemblyModule):
* wasm/js/WebAssemblyRuntimeErrorConstructor.cpp:
(JSC::constructJSWebAssemblyRuntimeError):
* wasm/js/WebAssemblyTableConstructor.cpp:
(JSC::constructJSWebAssemblyTable):
* wasm/js/WebAssemblyTablePrototype.cpp:
(JSC::webAssemblyTableProtoFuncLength):
(JSC::webAssemblyTableProtoFuncGrow):
(JSC::webAssemblyTableProtoFuncGet):
(JSC::webAssemblyTableProtoFuncSet):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@210038 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/wasm/JSWebAssembly.cpp
Source/JavaScriptCore/wasm/js/WebAssemblyCompileErrorConstructor.cpp
Source/JavaScriptCore/wasm/js/WebAssemblyFunction.cpp
Source/JavaScriptCore/wasm/js/WebAssemblyInstanceConstructor.cpp
Source/JavaScriptCore/wasm/js/WebAssemblyMemoryConstructor.cpp
Source/JavaScriptCore/wasm/js/WebAssemblyModuleConstructor.cpp
Source/JavaScriptCore/wasm/js/WebAssemblyRuntimeErrorConstructor.cpp
Source/JavaScriptCore/wasm/js/WebAssemblyTableConstructor.cpp
Source/JavaScriptCore/wasm/js/WebAssemblyTablePrototype.cpp

index 6928c0a..feeefac 100644 (file)
@@ -1,3 +1,39 @@
+2016-12-20  JF Bastien  <jfbastien@apple.com>
+
+        WebAssembly: construct 32-bit encodedJSValue properly
+        https://bugs.webkit.org/show_bug.cgi?id=166199
+
+        Reviewed by Mark Lam.
+
+        Constructing an encodedJSValue using `{ }` yields the wrong value
+        on 32-bit platforms. WebAssembly doesn't currently target 32-bit
+        platforms, but we may as well get it right.
+
+        * wasm/JSWebAssembly.cpp:
+        (JSC::webAssemblyCompileFunc):
+        (JSC::webAssemblyValidateFunc):
+        * wasm/js/JSWebAssemblyHelpers.h:
+        (JSC::toNonWrappingUint32):
+        * wasm/js/WebAssemblyCompileErrorConstructor.cpp:
+        (JSC::constructJSWebAssemblyCompileError):
+        * wasm/js/WebAssemblyFunction.cpp:
+        (JSC::callWebAssemblyFunction):
+        * wasm/js/WebAssemblyInstanceConstructor.cpp:
+        (JSC::constructJSWebAssemblyInstance):
+        * wasm/js/WebAssemblyMemoryConstructor.cpp:
+        (JSC::constructJSWebAssemblyMemory):
+        * wasm/js/WebAssemblyModuleConstructor.cpp:
+        (JSC::constructJSWebAssemblyModule):
+        * wasm/js/WebAssemblyRuntimeErrorConstructor.cpp:
+        (JSC::constructJSWebAssemblyRuntimeError):
+        * wasm/js/WebAssemblyTableConstructor.cpp:
+        (JSC::constructJSWebAssemblyTable):
+        * wasm/js/WebAssemblyTablePrototype.cpp:
+        (JSC::webAssemblyTableProtoFuncLength):
+        (JSC::webAssemblyTableProtoFuncGrow):
+        (JSC::webAssemblyTableProtoFuncGet):
+        (JSC::webAssemblyTableProtoFuncSet):
+
 2016-12-20  Dean Jackson  <dino@apple.com>
 
         Remove INDIE_UI
index 161e94b..a6fc40d 100644 (file)
@@ -49,7 +49,7 @@ EncodedJSValue JSC_HOST_CALL webAssemblyCompileFunc(ExecState* exec)
     auto catchScope = DECLARE_CATCH_SCOPE(vm);
 
     JSPromiseDeferred* promise = JSPromiseDeferred::create(exec, exec->lexicalGlobalObject());
-    RETURN_IF_EXCEPTION(catchScope, { });
+    RETURN_IF_EXCEPTION(catchScope, encodedJSValue());
 
     // FIXME: Make this truly asynchronous:
     // https://bugs.webkit.org/show_bug.cgi?id=166016
@@ -72,7 +72,7 @@ EncodedJSValue JSC_HOST_CALL webAssemblyValidateFunc(ExecState* exec)
     size_t byteOffset;
     size_t byteSize;
     uint8_t* base = getWasmBufferFromValue(exec, exec->argument(0), byteOffset, byteSize);
-    RETURN_IF_EXCEPTION(scope, { });
+    RETURN_IF_EXCEPTION(scope, encodedJSValue());
     Wasm::Plan plan(&vm, base + byteOffset, byteSize);
     // FIXME: We might want to throw an OOM exception here if we detect that something will OOM.
     // https://bugs.webkit.org/show_bug.cgi?id=166015
index 0a0a2ab..d68567a 100644 (file)
@@ -50,7 +50,7 @@ static EncodedJSValue JSC_HOST_CALL constructJSWebAssemblyCompileError(ExecState
     auto scope = DECLARE_THROW_SCOPE(vm);
     JSValue message = state->argument(0);
     auto* structure = InternalFunction::createSubclassStructure(state, state->newTarget(), asInternalFunction(state->jsCallee())->globalObject()->WebAssemblyCompileErrorStructure());
-    RETURN_IF_EXCEPTION(scope, { });
+    RETURN_IF_EXCEPTION(scope, encodedJSValue());
     return JSValue::encode(JSWebAssemblyCompileError::create(state, structure, message, false));
 }
 
index 0fa2ef7..4f0d7a8 100644 (file)
@@ -79,7 +79,7 @@ static EncodedJSValue JSC_HOST_CALL callWebAssemblyFunction(ExecState* exec)
         case Wasm::Anyfunc:
             RELEASE_ASSERT_NOT_REACHED();
         }
-        RETURN_IF_EXCEPTION(scope, { });
+        RETURN_IF_EXCEPTION(scope, encodedJSValue());
         boxedArgs.append(arg);
     }
 
index 61f58a7..d63e839 100644 (file)
@@ -77,13 +77,13 @@ static EncodedJSValue JSC_HOST_CALL constructJSWebAssemblyInstance(ExecState* ex
 
     Identifier moduleKey = Identifier::fromUid(PrivateName(PrivateName::Description, "WebAssemblyInstance"));
     WebAssemblyModuleRecord* moduleRecord = WebAssemblyModuleRecord::create(exec, vm, globalObject->webAssemblyModuleRecordStructure(), moduleKey, moduleInformation);
-    RETURN_IF_EXCEPTION(throwScope, { });
+    RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
 
     Structure* instanceStructure = InternalFunction::createSubclassStructure(exec, exec->newTarget(), globalObject->WebAssemblyInstanceStructure());
-    RETURN_IF_EXCEPTION(throwScope, { });
+    RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
 
     JSWebAssemblyInstance* instance = JSWebAssemblyInstance::create(vm, instanceStructure, jsModule, moduleRecord->getModuleNamespace(exec));
-    RETURN_IF_EXCEPTION(throwScope, { });
+    RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
 
     // Let funcs, memories and tables be initially-empty lists of callable JavaScript objects, WebAssembly.Memory objects and WebAssembly.Table objects, respectively.
     // Let imports be an initially-empty list of external values.
@@ -96,7 +96,7 @@ static EncodedJSValue JSC_HOST_CALL constructJSWebAssemblyInstance(ExecState* ex
     for (auto& import : moduleInformation.imports) {
         // 1. Let o be the resultant value of performing Get(importObject, i.module_name).
         JSValue importModuleValue = importObject->get(exec, import.module);
-        RETURN_IF_EXCEPTION(throwScope, { });
+        RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
         // 2. If Type(o) is not Object, throw a TypeError.
         if (!importModuleValue.isObject())
             return JSValue::encode(throwException(exec, throwScope, createTypeError(exec, ASCIILiteral("import must be an object"), defaultSourceAppender, runtimeTypeForValue(importModuleValue))));
@@ -104,7 +104,7 @@ static EncodedJSValue JSC_HOST_CALL constructJSWebAssemblyInstance(ExecState* ex
         // 3. Let v be the value of performing Get(o, i.item_name)
         JSObject* object = jsCast<JSObject*>(importModuleValue);
         JSValue value = object->get(exec, import.field);
-        RETURN_IF_EXCEPTION(throwScope, { });
+        RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
 
         switch (import.kind) {
         case Wasm::ExternalKind::Function: {
@@ -271,13 +271,13 @@ static EncodedJSValue JSC_HOST_CALL constructJSWebAssemblyInstance(ExecState* ex
     }
 
     moduleRecord->link(exec, instance);
-    RETURN_IF_EXCEPTION(throwScope, { });
+    RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
 
     if (verbose)
         moduleRecord->dump();
     JSValue startResult = moduleRecord->evaluate(exec);
     UNUSED_PARAM(startResult);
-    RETURN_IF_EXCEPTION(throwScope, { });
+    RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
 
     return JSValue::encode(instance);
 }
index f4b4103..3f88ed4 100644 (file)
@@ -67,9 +67,9 @@ static EncodedJSValue JSC_HOST_CALL constructJSWebAssemblyMemory(ExecState* exec
     {
         Identifier initial = Identifier::fromString(&vm, "initial");
         JSValue minSizeValue = memoryDescriptor->get(exec, initial);
-        RETURN_IF_EXCEPTION(throwScope, { });
+        RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
         uint32_t size = toNonWrappingUint32(exec, minSizeValue);
-        RETURN_IF_EXCEPTION(throwScope, { });
+        RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
         if (!Wasm::PageCount::isValid(size))
             return JSValue::encode(throwException(exec, throwScope, createRangeError(exec, ASCIILiteral("WebAssembly.Memory 'initial' page count is too large"))));
         initialPageCount = Wasm::PageCount(size);
@@ -79,12 +79,12 @@ static EncodedJSValue JSC_HOST_CALL constructJSWebAssemblyMemory(ExecState* exec
     {
         Identifier maximum = Identifier::fromString(&vm, "maximum");
         bool hasProperty = memoryDescriptor->hasProperty(exec, maximum);
-        RETURN_IF_EXCEPTION(throwScope, { });
+        RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
         if (hasProperty) {
             JSValue maxSizeValue = memoryDescriptor->get(exec, maximum);
-            RETURN_IF_EXCEPTION(throwScope, { });
+            RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
             uint32_t size = toNonWrappingUint32(exec, maxSizeValue);
-            RETURN_IF_EXCEPTION(throwScope, { });
+            RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
             if (!Wasm::PageCount::isValid(size))
                 return JSValue::encode(throwException(exec, throwScope, createRangeError(exec, ASCIILiteral("WebAssembly.Memory 'maximum' page count is too large"))));
             maximumPageCount = Wasm::PageCount(size);
index 2673fc0..73ca7a4 100644 (file)
@@ -58,7 +58,7 @@ static EncodedJSValue JSC_HOST_CALL constructJSWebAssemblyModule(ExecState* exec
     VM& vm = exec->vm();
     auto throwScope = DECLARE_THROW_SCOPE(vm);
     auto* structure = InternalFunction::createSubclassStructure(exec, exec->newTarget(), exec->lexicalGlobalObject()->WebAssemblyModuleStructure());
-    RETURN_IF_EXCEPTION(throwScope, { });
+    RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
     throwScope.release();
     return JSValue::encode(WebAssemblyModuleConstructor::createModule(exec, structure));
 }
index 7ef102e..920db83 100644 (file)
@@ -50,7 +50,7 @@ static EncodedJSValue JSC_HOST_CALL constructJSWebAssemblyRuntimeError(ExecState
     auto scope = DECLARE_THROW_SCOPE(vm);
     JSValue message = state->argument(0);
     auto* structure = InternalFunction::createSubclassStructure(state, state->newTarget(), asInternalFunction(state->jsCallee())->globalObject()->WebAssemblyRuntimeErrorStructure());
-    RETURN_IF_EXCEPTION(scope, { });
+    RETURN_IF_EXCEPTION(scope, encodedJSValue());
     return JSValue::encode(JSWebAssemblyRuntimeError::create(state, structure, message, false));
 }
 
index a9ac152..12d27ab 100644 (file)
@@ -61,28 +61,28 @@ static EncodedJSValue JSC_HOST_CALL constructJSWebAssemblyTable(ExecState* exec)
     {
         Identifier elementIdent = Identifier::fromString(&vm, "element");
         JSValue elementValue = memoryDescriptor->get(exec, elementIdent);
-        RETURN_IF_EXCEPTION(throwScope, { });
+        RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
         String elementString = elementValue.toWTFString(exec);
-        RETURN_IF_EXCEPTION(throwScope, { });
+        RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
         if (elementString != "anyfunc")
             return JSValue::encode(throwException(exec, throwScope, createTypeError(exec, ASCIILiteral("WebAssembly.Table expects its 'element' field to be the string 'anyfunc'"))));
     }
 
     Identifier initialIdent = Identifier::fromString(&vm, "initial");
     JSValue initialSizeValue = memoryDescriptor->get(exec, initialIdent);
-    RETURN_IF_EXCEPTION(throwScope, { });
+    RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
     uint32_t initial = toNonWrappingUint32(exec, initialSizeValue);
-    RETURN_IF_EXCEPTION(throwScope, { });
+    RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
 
     std::optional<uint32_t> maximum;
     Identifier maximumIdent = Identifier::fromString(&vm, "maximum");
     bool hasProperty = memoryDescriptor->hasProperty(exec, maximumIdent);
-    RETURN_IF_EXCEPTION(throwScope, { });
+    RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
     if (hasProperty) {
         JSValue maxSizeValue = memoryDescriptor->get(exec, maximumIdent);
-        RETURN_IF_EXCEPTION(throwScope, { });
+        RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
         maximum = toNonWrappingUint32(exec, maxSizeValue);
-        RETURN_IF_EXCEPTION(throwScope, { });
+        RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
 
         if (initial > *maximum) {
             return JSValue::encode(throwException(exec, throwScope,
index 3b1a064..83392f4 100644 (file)
@@ -67,7 +67,7 @@ EncodedJSValue JSC_HOST_CALL webAssemblyTableProtoFuncLength(ExecState* exec)
     auto throwScope = DECLARE_THROW_SCOPE(vm);
 
     JSWebAssemblyTable* table = getTable(exec, vm, exec->thisValue());
-    RETURN_IF_EXCEPTION(throwScope, { });
+    RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
     return JSValue::encode(jsNumber(table->size()));
 }
 
@@ -77,10 +77,10 @@ EncodedJSValue JSC_HOST_CALL webAssemblyTableProtoFuncGrow(ExecState* exec)
     auto throwScope = DECLARE_THROW_SCOPE(vm);
 
     JSWebAssemblyTable* table = getTable(exec, vm, exec->thisValue());
-    RETURN_IF_EXCEPTION(throwScope, { });
+    RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
 
     uint32_t index = toNonWrappingUint32(exec, exec->argument(0));
-    RETURN_IF_EXCEPTION(throwScope, { });
+    RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
     if (!table->grow(index)) {
         throwException(exec, throwScope,
             createTypeError(exec, ASCIILiteral("WebAssembly.Table.prototype.grow could not grow the table")));
@@ -96,10 +96,10 @@ EncodedJSValue JSC_HOST_CALL webAssemblyTableProtoFuncGet(ExecState* exec)
     auto throwScope = DECLARE_THROW_SCOPE(vm);
 
     JSWebAssemblyTable* table = getTable(exec, vm, exec->thisValue());
-    RETURN_IF_EXCEPTION(throwScope, { });
+    RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
 
     uint32_t index = toNonWrappingUint32(exec, exec->argument(0));
-    RETURN_IF_EXCEPTION(throwScope, { });
+    RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
     if (index >= table->size()) {
         throwException(exec, throwScope,
             createRangeError(exec, ASCIILiteral("WebAssembly.Table.prototype.get expects an integer less than the size of the table")));
@@ -117,7 +117,7 @@ EncodedJSValue JSC_HOST_CALL webAssemblyTableProtoFuncSet(ExecState* exec)
     auto throwScope = DECLARE_THROW_SCOPE(vm);
 
     JSWebAssemblyTable* table = getTable(exec, vm, exec->thisValue());
-    RETURN_IF_EXCEPTION(throwScope, { });
+    RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
 
     JSValue value = exec->argument(1);
     WebAssemblyFunction* function = jsDynamicCast<WebAssemblyFunction*>(value);
@@ -128,7 +128,7 @@ EncodedJSValue JSC_HOST_CALL webAssemblyTableProtoFuncSet(ExecState* exec)
     }
 
     uint32_t index = toNonWrappingUint32(exec, exec->argument(0));
-    RETURN_IF_EXCEPTION(throwScope, { });
+    RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
 
     if (index >= table->size()) {
         throwException(exec, throwScope,