Changeset 272119 in webkit


Ignore:
Timestamp:
Jan 30, 2021 11:51:08 AM (18 months ago)
Author:
ysuzuki@apple.com
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):

Location:
trunk/Source/JavaScriptCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r272099 r272119  
     12021-01-30  Yusuke Suzuki  <ysuzuki@apple.com>
     2
     3        Unreviewed, fix after r272071
     4        https://bugs.webkit.org/show_bug.cgi?id=220914
     5
     6        Since WebAssembly.Global can be "immutable", we cannot use Wasm::Global::set when setting an initial value.
     7
     8        * wasm/js/WebAssemblyGlobalConstructor.cpp:
     9        (JSC::JSC_DEFINE_HOST_FUNCTION):
     10
    1112021-01-29  Yusuke Suzuki  <ysuzuki@apple.com>
    212
  • trunk/Source/JavaScriptCore/wasm/js/WebAssemblyGlobalConstructor.cpp

    r272081 r272119  
    105105    uint64_t initialValue = 0;
    106106    JSValue argument = callFrame->argument(1);
    107     if (!argument.isUndefined()) {
    108         switch (type) {
    109         case Wasm::Type::I32: {
     107    switch (type) {
     108    case Wasm::Type::I32: {
     109        if (!argument.isUndefined()) {
    110110            int32_t value = argument.toInt32(globalObject);
    111111            RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
    112112            initialValue = static_cast<uint64_t>(bitwise_cast<uint32_t>(value));
    113             break;
    114         }
    115         case Wasm::Type::I64: {
     113        }
     114        break;
     115    }
     116    case Wasm::Type::I64: {
     117        if (!argument.isUndefined()) {
    116118            int64_t value = argument.toBigInt64(globalObject);
    117119            RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
    118120            initialValue = static_cast<uint64_t>(value);
    119             break;
    120         }
    121         case Wasm::Type::F32: {
     121        }
     122        break;
     123    }
     124    case Wasm::Type::F32: {
     125        if (!argument.isUndefined()) {
    122126            float value = argument.toFloat(globalObject);
    123127            RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
    124128            initialValue = static_cast<uint64_t>(bitwise_cast<uint32_t>(value));
    125             break;
    126         }
    127         case Wasm::Type::F64: {
     129        }
     130        break;
     131    }
     132    case Wasm::Type::F64: {
     133        if (!argument.isUndefined()) {
    128134            double value = argument.toNumber(globalObject);
    129135            RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
    130136            initialValue = bitwise_cast<uint64_t>(value);
    131             break;
    132         }
    133         case Wasm::Type::Funcref:
    134         case Wasm::Type::Externref: {
    135             // We check default value for these types later in set method.
    136             ASSERT(Options::useWebAssemblyReferences());
    137             break;
    138         }
    139         default:
    140             RELEASE_ASSERT_NOT_REACHED();
    141         }
     137        }
     138        break;
     139    }
     140    case Wasm::Type::Funcref: {
     141        ASSERT(Options::useWebAssemblyReferences());
     142        if (argument.isUndefined())
     143            argument = defaultValueForReferenceType(type);
     144        if (!isWebAssemblyHostFunction(vm, argument) && !argument.isNull()) {
     145            throwException(globalObject, throwScope, createJSWebAssemblyRuntimeError(globalObject, vm, "Funcref must be an exported wasm function"));
     146            return { };
     147        }
     148        initialValue = JSValue::encode(argument);
     149        break;
     150    }
     151    case Wasm::Type::Externref: {
     152        ASSERT(Options::useWebAssemblyReferences());
     153        if (argument.isUndefined())
     154            argument = defaultValueForReferenceType(type);
     155        initialValue = JSValue::encode(argument);
     156        break;
     157    }
     158    default:
     159        RELEASE_ASSERT_NOT_REACHED();
    142160    }
    143161
     
    145163    JSWebAssemblyGlobal* jsWebAssemblyGlobal = JSWebAssemblyGlobal::tryCreate(globalObject, vm, webAssemblyGlobalStructure, WTFMove(wasmGlobal));
    146164    RETURN_IF_EXCEPTION(throwScope, { });
    147 
    148     if (Wasm::isRefType(type)) {
    149         ASSERT(Options::useWebAssemblyReferences());
    150         if (argument.isUndefined())
    151             argument = defaultValueForReferenceType(type);
    152         jsWebAssemblyGlobal->global()->set(globalObject, argument);
    153         RETURN_IF_EXCEPTION(throwScope, { });
    154     }
     165    ensureStillAliveHere(bitwise_cast<void*>(initialValue)); // Ensure this is kept alive while creating JSWebAssemblyGlobal.
    155166    return JSValue::encode(jsWebAssemblyGlobal);
    156167}
Note: See TracChangeset for help on using the changeset viewer.