Skip to content

Commit 3f8aa6d

Browse files
thibaudmichaudguybedford
authored andcommitted
deps: V8: backport 9997fc013952
Original commit message: [wasm][exnref] Use wasm_null for exnref A JS null caught in wasm as an exnref with catch_(all_)ref should be observably different from a null exnref: a JS null should behave like a regular JS exception with null as the externref package, while a null exnref is the actual null value for this type. In particular, a JS null exception can be rethrown while a null exnref cannot. Represent null exnrefs with wasm_null instead of JS null to avoid the confusion. [email protected] Fixed: 374790906 Change-Id: If9f16a24407ee7d1399613255c3f14e0a6ebef9e Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/5953226 Reviewed-by: Jakob Kummerow <[email protected]> Commit-Queue: Thibaud Michaud <[email protected]> Cr-Commit-Position: refs/heads/main@{#96782} Refs: v8/v8@9997fc013952
1 parent fa4d078 commit 3f8aa6d

7 files changed

Lines changed: 23 additions & 15 deletions

File tree

deps/v8/src/builtins/wasm.tq

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,12 @@ builtin WasmThrow(tag: Object, values: FixedArray): JSAny {
373373
}
374374

375375
builtin WasmRethrow(exception: Object): JSAny {
376-
if (exception == Null) tail ThrowWasmTrapRethrowNull();
376+
dcheck(exception != kWasmNull);
377+
tail runtime::WasmReThrow(LoadContextFromFrame(), exception);
378+
}
379+
380+
builtin WasmThrowRef(exception: Object): JSAny {
381+
if (exception == kWasmNull) tail ThrowWasmTrapRethrowNull();
377382
tail runtime::WasmReThrow(LoadContextFromFrame(), exception);
378383
}
379384

deps/v8/src/compiler/wasm-compiler.cc

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -391,10 +391,8 @@ Node* WasmGraphBuilder::EffectPhi(unsigned count, Node** effects_and_control) {
391391
Node* WasmGraphBuilder::RefNull(wasm::ValueType type) {
392392
// We immediately lower null in wrappers, as they do not go through a lowering
393393
// phase.
394-
// TODO(thibaudm): Can we use wasm null for exnref?
395394
return parameter_mode_ == kInstanceParameterMode ? gasm_->Null(type)
396-
: (type == wasm::kWasmExternRef || type == wasm::kWasmNullExternRef ||
397-
type == wasm::kWasmExnRef || type == wasm::kWasmNullExnRef)
395+
: (type == wasm::kWasmExternRef || type == wasm::kWasmNullExternRef)
398396
? LOAD_ROOT(NullValue, null_value)
399397
: LOAD_ROOT(WasmNull, wasm_null);
400398
}
@@ -2372,6 +2370,14 @@ Node* WasmGraphBuilder::Rethrow(Node* except_obj) {
23722370
Builtin::kWasmRethrow, Operator::kNoProperties, except_obj);
23732371
}
23742372

2373+
Node* WasmGraphBuilder::ThrowRef(Node* except_obj) {
2374+
// TODO(v8:8091): Currently the message of the original exception is not being
2375+
// preserved when rethrown to the console. The pending message will need to be
2376+
// saved when caught and restored here while being rethrown.
2377+
return gasm_->CallBuiltinThroughJumptable(
2378+
Builtin::kWasmThrowRef, Operator::kNoProperties, except_obj);
2379+
}
2380+
23752381
Node* WasmGraphBuilder::IsExceptionTagUndefined(Node* tag) {
23762382
return gasm_->TaggedEqual(tag, UndefinedValue());
23772383
}

deps/v8/src/compiler/wasm-compiler.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ class WasmGraphBuilder {
233233
const base::Vector<Node*> values,
234234
wasm::WasmCodePosition position);
235235
Node* Rethrow(Node* except_obj);
236+
Node* ThrowRef(Node* except_obj);
236237
Node* IsExceptionTagUndefined(Node* tag);
237238
Node* LoadJSTag();
238239
Node* ExceptionTagEqual(Node* caught_tag, Node* expected_tag);

deps/v8/src/wasm/baseline/liftoff-compiler.cc

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1668,7 +1668,7 @@ class LiftoffCompiler {
16681668
void ThrowRef(FullDecoder* decoder, Value*) {
16691669
// Like Rethrow, but pops the exception from the stack.
16701670
VarState exn = __ PopVarState();
1671-
CallBuiltin(Builtin::kWasmRethrow, MakeSig::Params(kRef), {exn},
1671+
CallBuiltin(Builtin::kWasmThrowRef, MakeSig::Params(kRef), {exn},
16721672
decoder->position());
16731673
int pc_offset = __ pc_offset();
16741674
MaybeOSR();
@@ -8253,11 +8253,9 @@ class LiftoffCompiler {
82538253
}
82548254

82558255
void LoadNullValue(Register null, ValueType type) {
8256-
// TODO(thibaudm): Can we use wasm null for exnref?
82578256
__ LoadFullPointer(
82588257
null, kRootRegister,
8259-
type == kWasmExternRef || type == kWasmNullExternRef ||
8260-
type == kWasmExnRef || type == kWasmNullExnRef
8258+
type == kWasmExternRef || type == kWasmNullExternRef
82618259
? IsolateData::root_slot_offset(RootIndex::kNullValue)
82628260
: IsolateData::root_slot_offset(RootIndex::kWasmNull));
82638261
}
@@ -8270,8 +8268,7 @@ class LiftoffCompiler {
82708268
ValueType type) {
82718269
#if V8_STATIC_ROOTS_BOOL
82728270
// TODO(14616): Extend this for shared types.
8273-
bool is_wasm_null = type != kWasmExternRef && type != kWasmNullExternRef &&
8274-
type != kWasmExnRef && type != kWasmNullExnRef;
8271+
bool is_wasm_null = type != kWasmExternRef && type != kWasmNullExternRef;
82758272
uint32_t value = is_wasm_null ? StaticReadOnlyRoot::kWasmNull
82768273
: StaticReadOnlyRoot::kNullValue;
82778274
__ LoadConstant(LiftoffRegister(null),

deps/v8/src/wasm/constant-expression-interface.cc

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,7 @@ void ConstantExpressionInterface::RefNull(FullDecoder* decoder, ValueType type,
105105
Value* result) {
106106
if (!generate_value()) return;
107107
result->runtime_value =
108-
WasmValue((IsSubtypeOf(type, kWasmExternRef, decoder->module_) ||
109-
IsSubtypeOf(type, kWasmExnRef, decoder->module_))
108+
WasmValue(IsSubtypeOf(type, kWasmExternRef, decoder->module_)
110109
? Handle<Object>::cast(isolate_->factory()->null_value())
111110
: Handle<Object>::cast(isolate_->factory()->wasm_null()),
112111
type);
@@ -201,8 +200,7 @@ WasmValue DefaultValueForType(ValueType type, Isolate* isolate) {
201200
return WasmValue(Simd128());
202201
case kRefNull:
203202
return WasmValue(
204-
type == kWasmExternRef || type == kWasmNullExternRef ||
205-
type == kWasmExnRef || type == kWasmNullExnRef
203+
type == kWasmExternRef || type == kWasmNullExternRef
206204
? Handle<Object>::cast(isolate->factory()->null_value())
207205
: Handle<Object>::cast(isolate->factory()->wasm_null()),
208206
type);

deps/v8/src/wasm/graph-builder-interface.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2799,7 +2799,7 @@ class WasmGraphBuildingInterface {
27992799

28002800
void ThrowRef(FullDecoder* decoder, TFNode* exception) {
28012801
DCHECK_NOT_NULL(exception);
2802-
CheckForException(decoder, builder_->Rethrow(exception), false);
2802+
CheckForException(decoder, builder_->ThrowRef(exception), false);
28032803
builder_->TerminateThrow(effect(), control());
28042804
}
28052805
};

deps/v8/src/wasm/wasm-builtin-list.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ namespace v8::internal::wasm {
5151
V(WasmAllocateFixedArray) \
5252
V(WasmThrow) \
5353
V(WasmRethrow) \
54+
V(WasmThrowRef) \
5455
V(WasmRethrowExplicitContext) \
5556
V(WasmTraceEnter) \
5657
V(WasmTraceExit) \

0 commit comments

Comments
 (0)