diff options
Diffstat (limited to 'js/src/wasm/WasmValidate.cpp')
-rw-r--r-- | js/src/wasm/WasmValidate.cpp | 84 |
1 files changed, 22 insertions, 62 deletions
diff --git a/js/src/wasm/WasmValidate.cpp b/js/src/wasm/WasmValidate.cpp index e964c11d04..98a1423a41 100644 --- a/js/src/wasm/WasmValidate.cpp +++ b/js/src/wasm/WasmValidate.cpp @@ -89,14 +89,19 @@ bool wasm::EncodeLocalEntries(Encoder& e, const ValTypeVector& locals) { return true; } -bool wasm::DecodeLocalEntries(Decoder& d, const TypeContext& types, - const FeatureArgs& features, - ValTypeVector* locals) { +bool wasm::DecodeLocalEntriesWithParams(Decoder& d, + const ModuleEnvironment& env, + uint32_t funcIndex, + ValTypeVector* locals) { uint32_t numLocalEntries; if (!d.readVarU32(&numLocalEntries)) { return d.fail("failed to read number of local entries"); } + if (!locals->appendAll(env.funcs[funcIndex].type->args())) { + return false; + } + for (uint32_t i = 0; i < numLocalEntries; i++) { uint32_t count; if (!d.readVarU32(&count)) { @@ -108,7 +113,7 @@ bool wasm::DecodeLocalEntries(Decoder& d, const TypeContext& types, } ValType type; - if (!d.readValType(types, features, &type)) { + if (!d.readValType(*env.types, env.features, &type)) { return false; } @@ -235,9 +240,9 @@ static bool DecodeFunctionBodyExprs(const ModuleEnvironment& env, &unusedArgs)); } #endif -#ifdef ENABLE_WASM_FUNCTION_REFERENCES +#ifdef ENABLE_WASM_GC case uint16_t(Op::CallRef): { - if (!env.functionReferencesEnabled()) { + if (!env.gcEnabled()) { return iter.unrecognizedOpcode(&op); } const FuncType* unusedType; @@ -246,7 +251,7 @@ static bool DecodeFunctionBodyExprs(const ModuleEnvironment& env, } # ifdef ENABLE_WASM_TAIL_CALLS case uint16_t(Op::ReturnCallRef): { - if (!env.functionReferencesEnabled() || !env.tailCallsEnabled()) { + if (!env.gcEnabled() || !env.tailCallsEnabled()) { return iter.unrecognizedOpcode(&op); } const FuncType* unusedType; @@ -1240,15 +1245,15 @@ static bool DecodeFunctionBodyExprs(const ModuleEnvironment& env, } break; } -#ifdef ENABLE_WASM_FUNCTION_REFERENCES +#ifdef ENABLE_WASM_GC case uint16_t(Op::RefAsNonNull): { - if (!env.functionReferencesEnabled()) { + if (!env.gcEnabled()) { return iter.unrecognizedOpcode(&op); } CHECK(iter.readRefAsNonNull(¬hing)); } case uint16_t(Op::BrOnNull): { - if (!env.functionReferencesEnabled()) { + if (!env.gcEnabled()) { return iter.unrecognizedOpcode(&op); } uint32_t unusedDepth; @@ -1256,7 +1261,7 @@ static bool DecodeFunctionBodyExprs(const ModuleEnvironment& env, iter.readBrOnNull(&unusedDepth, &unusedType, ¬hings, ¬hing)); } case uint16_t(Op::BrOnNonNull): { - if (!env.functionReferencesEnabled()) { + if (!env.gcEnabled()) { return iter.unrecognizedOpcode(&op); } uint32_t unusedDepth; @@ -1285,31 +1290,19 @@ static bool DecodeFunctionBodyExprs(const ModuleEnvironment& env, CHECK(iter.readRefIsNull(¬hing)); } case uint16_t(Op::Try): - if (!env.exceptionsEnabled()) { - return iter.unrecognizedOpcode(&op); - } CHECK(iter.readTry(&unusedType)); case uint16_t(Op::Catch): { - if (!env.exceptionsEnabled()) { - return iter.unrecognizedOpcode(&op); - } LabelKind unusedKind; uint32_t unusedIndex; CHECK(iter.readCatch(&unusedKind, &unusedIndex, &unusedType, &unusedType, ¬hings)); } case uint16_t(Op::CatchAll): { - if (!env.exceptionsEnabled()) { - return iter.unrecognizedOpcode(&op); - } LabelKind unusedKind; CHECK(iter.readCatchAll(&unusedKind, &unusedType, &unusedType, ¬hings)); } case uint16_t(Op::Delegate): { - if (!env.exceptionsEnabled()) { - return iter.unrecognizedOpcode(&op); - } uint32_t unusedDepth; if (!iter.readDelegate(&unusedDepth, &unusedType, ¬hings)) { return false; @@ -1318,16 +1311,10 @@ static bool DecodeFunctionBodyExprs(const ModuleEnvironment& env, break; } case uint16_t(Op::Throw): { - if (!env.exceptionsEnabled()) { - return iter.unrecognizedOpcode(&op); - } uint32_t unusedIndex; CHECK(iter.readThrow(&unusedIndex, ¬hings)); } case uint16_t(Op::Rethrow): { - if (!env.exceptionsEnabled()) { - return iter.unrecognizedOpcode(&op); - } uint32_t unusedDepth; CHECK(iter.readRethrow(&unusedDepth)); } @@ -1541,14 +1528,10 @@ static bool DecodeFunctionBodyExprs(const ModuleEnvironment& env, bool wasm::ValidateFunctionBody(const ModuleEnvironment& env, uint32_t funcIndex, uint32_t bodySize, Decoder& d) { - ValTypeVector locals; - if (!locals.appendAll(env.funcs[funcIndex].type->args())) { - return false; - } - const uint8_t* bodyBegin = d.currentPosition(); - if (!DecodeLocalEntries(d, *env.types, env.features, &locals)) { + ValTypeVector locals; + if (!DecodeLocalEntriesWithParams(d, env, funcIndex, &locals)) { return false; } @@ -1624,7 +1607,7 @@ static bool DecodeFuncType(Decoder& d, ModuleEnvironment* env, static bool DecodeStructType(Decoder& d, ModuleEnvironment* env, StructType* structType) { if (!env->gcEnabled()) { - return d.fail("Structure types not enabled"); + return d.fail("gc not enabled"); } uint32_t numFields; @@ -1668,7 +1651,7 @@ static bool DecodeStructType(Decoder& d, ModuleEnvironment* env, static bool DecodeArrayType(Decoder& d, ModuleEnvironment* env, ArrayType* arrayType) { if (!env->gcEnabled()) { - return d.fail("gc types not enabled"); + return d.fail("gc not enabled"); } StorageType elementType; @@ -2247,13 +2230,6 @@ static bool CheckImportsAgainstBuiltinModules(Decoder& d, return true; } - // Allocate a type context for builtin types so we can canonicalize them - // and use them in type comparisons - RefPtr<TypeContext> builtinTypes = js_new<TypeContext>(); - if (!builtinTypes) { - return false; - } - uint32_t importFuncIndex = 0; for (auto& import : env->imports) { Maybe<BuiltinModuleId> builtinModule = @@ -2278,21 +2254,9 @@ static bool CheckImportsAgainstBuiltinModules(Decoder& d, return d.fail("unrecognized builtin module field"); } - // Get a canonicalized type definition for this builtin so we can - // accurately compare it against the import type. - FuncType builtinFuncType; - if (!(*builtinFunc)->funcType(&builtinFuncType)) { - return false; - } - if (!builtinTypes->addType(builtinFuncType)) { - return false; - } - const TypeDef& builtinTypeDef = - builtinTypes->type(builtinTypes->length() - 1); - const TypeDef& importTypeDef = (*env->types)[func.typeIndex]; - if (!TypeDef::isSubTypeOf(&builtinTypeDef, &importTypeDef)) { - return d.failf("type mismatch in %s", (*builtinFunc)->exportName); + if (!TypeDef::isSubTypeOf((*builtinFunc)->typeDef(), &importTypeDef)) { + return d.failf("type mismatch in %s", (*builtinFunc)->exportName()); } break; } @@ -2479,10 +2443,6 @@ static bool DecodeTagSection(Decoder& d, ModuleEnvironment* env) { return true; } - if (!env->exceptionsEnabled()) { - return d.fail("exceptions not enabled"); - } - uint32_t numDefs; if (!d.readVarU32(&numDefs)) { return d.fail("expected number of tags"); |