Title: [272119] trunk/Source/_javascript_Core
Revision
272119
Author
[email protected]
Date
2021-01-30 11:51:08 -0800 (Sat, 30 Jan 2021)

Log Message

Unreviewed, fix after r272071
https://bugs.webkit.org/show_bug.cgi?id=220914

Since WebAssembly.Global can be "immutable", we cannot use Wasm::Global::set when setting an initial value.

* wasm/js/WebAssemblyGlobalConstructor.cpp:
(JSC::JSC_DEFINE_HOST_FUNCTION):

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/ChangeLog (272118 => 272119)


--- trunk/Source/_javascript_Core/ChangeLog	2021-01-30 19:34:48 UTC (rev 272118)
+++ trunk/Source/_javascript_Core/ChangeLog	2021-01-30 19:51:08 UTC (rev 272119)
@@ -1,3 +1,13 @@
+2021-01-30  Yusuke Suzuki  <[email protected]>
+
+        Unreviewed, fix after r272071
+        https://bugs.webkit.org/show_bug.cgi?id=220914
+
+        Since WebAssembly.Global can be "immutable", we cannot use Wasm::Global::set when setting an initial value.
+
+        * wasm/js/WebAssemblyGlobalConstructor.cpp:
+        (JSC::JSC_DEFINE_HOST_FUNCTION):
+
 2021-01-29  Yusuke Suzuki  <[email protected]>
 
         [JSC] Adjust property order of host JSFunction

Modified: trunk/Source/_javascript_Core/wasm/js/WebAssemblyGlobalConstructor.cpp (272118 => 272119)


--- trunk/Source/_javascript_Core/wasm/js/WebAssemblyGlobalConstructor.cpp	2021-01-30 19:34:48 UTC (rev 272118)
+++ trunk/Source/_javascript_Core/wasm/js/WebAssemblyGlobalConstructor.cpp	2021-01-30 19:51:08 UTC (rev 272119)
@@ -104,54 +104,65 @@
 
     uint64_t initialValue = 0;
     JSValue argument = callFrame->argument(1);
-    if (!argument.isUndefined()) {
-        switch (type) {
-        case Wasm::Type::I32: {
+    switch (type) {
+    case Wasm::Type::I32: {
+        if (!argument.isUndefined()) {
             int32_t value = argument.toInt32(globalObject);
             RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
             initialValue = static_cast<uint64_t>(bitwise_cast<uint32_t>(value));
-            break;
         }
-        case Wasm::Type::I64: {
+        break;
+    }
+    case Wasm::Type::I64: {
+        if (!argument.isUndefined()) {
             int64_t value = argument.toBigInt64(globalObject);
             RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
             initialValue = static_cast<uint64_t>(value);
-            break;
         }
-        case Wasm::Type::F32: {
+        break;
+    }
+    case Wasm::Type::F32: {
+        if (!argument.isUndefined()) {
             float value = argument.toFloat(globalObject);
             RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
             initialValue = static_cast<uint64_t>(bitwise_cast<uint32_t>(value));
-            break;
         }
-        case Wasm::Type::F64: {
+        break;
+    }
+    case Wasm::Type::F64: {
+        if (!argument.isUndefined()) {
             double value = argument.toNumber(globalObject);
             RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
             initialValue = bitwise_cast<uint64_t>(value);
-            break;
         }
-        case Wasm::Type::Funcref:
-        case Wasm::Type::Externref: {
-            // We check default value for these types later in set method.
-            ASSERT(Options::useWebAssemblyReferences());
-            break;
+        break;
+    }
+    case Wasm::Type::Funcref: {
+        ASSERT(Options::useWebAssemblyReferences());
+        if (argument.isUndefined())
+            argument = defaultValueForReferenceType(type);
+        if (!isWebAssemblyHostFunction(vm, argument) && !argument.isNull()) {
+            throwException(globalObject, throwScope, createJSWebAssemblyRuntimeError(globalObject, vm, "Funcref must be an exported wasm function"));
+            return { };
         }
-        default:
-            RELEASE_ASSERT_NOT_REACHED();
-        }
+        initialValue = JSValue::encode(argument);
+        break;
     }
+    case Wasm::Type::Externref: {
+        ASSERT(Options::useWebAssemblyReferences());
+        if (argument.isUndefined())
+            argument = defaultValueForReferenceType(type);
+        initialValue = JSValue::encode(argument);
+        break;
+    }
+    default:
+        RELEASE_ASSERT_NOT_REACHED();
+    }
 
     Ref<Wasm::Global> wasmGlobal = Wasm::Global::create(type, mutability, initialValue);
     JSWebAssemblyGlobal* jsWebAssemblyGlobal = JSWebAssemblyGlobal::tryCreate(globalObject, vm, webAssemblyGlobalStructure, WTFMove(wasmGlobal));
     RETURN_IF_EXCEPTION(throwScope, { });
-
-    if (Wasm::isRefType(type)) {
-        ASSERT(Options::useWebAssemblyReferences());
-        if (argument.isUndefined())
-            argument = defaultValueForReferenceType(type);
-        jsWebAssemblyGlobal->global()->set(globalObject, argument);
-        RETURN_IF_EXCEPTION(throwScope, { });
-    }
+    ensureStillAliveHere(bitwise_cast<void*>(initialValue)); // Ensure this is kept alive while creating JSWebAssemblyGlobal.
     return JSValue::encode(jsWebAssemblyGlobal);
 }
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to