Skip to content

Commit 746b4c9

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. R=jkummerow@chromium.org Fixed: 374790906 Change-Id: If9f16a24407ee7d1399613255c3f14e0a6ebef9e Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/5953226 Reviewed-by: Jakob Kummerow <jkummerow@chromium.org> Commit-Queue: Thibaud Michaud <thibaudm@chromium.org> Cr-Commit-Position: refs/heads/main@{#96782} Refs: v8/v8@9997fc013952
1 parent ffa9627 commit 746b4c9

12 files changed

Lines changed: 118 additions & 81 deletions

common.gypi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838

3939
# Reset this number to 0 on major V8 upgrades.
4040
# Increment by one for each non-official patch applied to deps/v8.
41-
'v8_embedder_string': '-node.53',
41+
'v8_embedder_string': '-node.54',
4242

4343
##### V8 defaults for Node.js #####
4444

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/turboshaft/wasm-lowering-reducer.h

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,7 @@ class WasmLoweringReducer : public Next {
4646
#if V8_STATIC_ROOTS_BOOL
4747
// TODO(14616): Extend this for shared types.
4848
const bool is_wasm_null =
49-
!wasm::IsSubtypeOf(type, wasm::kWasmExternRef, module_) &&
50-
!wasm::IsSubtypeOf(type, wasm::kWasmExnRef, module_);
49+
!wasm::IsSubtypeOf(type, wasm::kWasmExternRef, module_);
5150
OpIndex null_value =
5251
__ UintPtrConstant(is_wasm_null ? StaticReadOnlyRoot::kWasmNull
5352
: StaticReadOnlyRoot::kNullValue);
@@ -68,8 +67,7 @@ class WasmLoweringReducer : public Next {
6867
// (3) the object might be a JS object.
6968
if (null_check_strategy_ == NullCheckStrategy::kExplicit ||
7069
wasm::IsSubtypeOf(wasm::kWasmI31Ref.AsNonNull(), type, module_) ||
71-
wasm::IsSubtypeOf(type, wasm::kWasmExternRef, module_) ||
72-
wasm::IsSubtypeOf(type, wasm::kWasmExnRef, module_)) {
70+
wasm::IsSubtypeOf(type, wasm::kWasmExternRef, module_)) {
7371
__ TrapIf(__ IsNull(object, type), OpIndex::Invalid(), trap_id);
7472
} else {
7573
// Otherwise, load the word after the map word.
@@ -919,11 +917,9 @@ class WasmLoweringReducer : public Next {
919917

920918
OpIndex Null(wasm::ValueType type) {
921919
OpIndex roots = __ LoadRootRegister();
922-
RootIndex index =
923-
wasm::IsSubtypeOf(type, wasm::kWasmExternRef, module_) ||
924-
wasm::IsSubtypeOf(type, wasm::kWasmExnRef, module_)
925-
? RootIndex::kNullValue
926-
: RootIndex::kWasmNull;
920+
RootIndex index = wasm::IsSubtypeOf(type, wasm::kWasmExternRef, module_)
921+
? RootIndex::kNullValue
922+
: RootIndex::kWasmNull;
927923
// We load WasmNull as a pointer here and not as a TaggedPointer because
928924
// WasmNull is stored uncompressed in the IsolateData, and a load of a
929925
// TaggedPointer loads compressed pointers. We do not bitcast the WasmNull

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/compiler/wasm-gc-lowering.cc

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,7 @@ Reduction WasmGCLowering::Reduce(Node* node) {
9595
}
9696

9797
Node* WasmGCLowering::Null(wasm::ValueType type) {
98-
// TODO(thibaudm): Can we use wasm null for exnref?
99-
RootIndex index = wasm::IsSubtypeOf(type, wasm::kWasmExternRef, module_) ||
100-
wasm::IsSubtypeOf(type, wasm::kWasmExnRef, module_)
98+
RootIndex index = wasm::IsSubtypeOf(type, wasm::kWasmExternRef, module_)
10199
? RootIndex::kNullValue
102100
: RootIndex::kWasmNull;
103101
return gasm_.LoadImmutable(MachineType::Pointer(), gasm_.LoadRootRegister(),
@@ -108,8 +106,7 @@ Node* WasmGCLowering::IsNull(Node* object, wasm::ValueType type) {
108106
#if V8_STATIC_ROOTS_BOOL
109107
// TODO(14616): Extend this for shared types.
110108
const bool is_wasm_null =
111-
!wasm::IsSubtypeOf(type, wasm::kWasmExternRef, module_) &&
112-
!wasm::IsSubtypeOf(type, wasm::kWasmExnRef, module_);
109+
!wasm::IsSubtypeOf(type, wasm::kWasmExternRef, module_);
113110
Node* null_value =
114111
gasm_.UintPtrConstant(is_wasm_null ? StaticReadOnlyRoot::kWasmNull
115112
: StaticReadOnlyRoot::kNullValue);
@@ -488,8 +485,7 @@ Reduction WasmGCLowering::ReduceAssertNotNull(Node* node) {
488485
if (null_check_strategy_ == NullCheckStrategy::kExplicit ||
489486
wasm::IsSubtypeOf(wasm::kWasmI31Ref.AsNonNull(), op_parameter.type,
490487
module_) ||
491-
wasm::IsSubtypeOf(op_parameter.type, wasm::kWasmExternRef, module_) ||
492-
wasm::IsSubtypeOf(op_parameter.type, wasm::kWasmExnRef, module_)) {
488+
wasm::IsSubtypeOf(op_parameter.type, wasm::kWasmExternRef, module_)) {
493489
gasm_.TrapIf(IsNull(object, op_parameter.type), op_parameter.trap_id);
494490
UpdateSourcePosition(gasm_.effect(), node);
495491
} else {

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

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -931,8 +931,7 @@ class LiftoffCompiler {
931931
ValueType type = decoder->local_types_[local_index];
932932
if (type.is_reference()) {
933933
__ Spill(__ cache_state()->stack_state[local_index].offset(),
934-
IsSubtypeOf(type, kWasmExternRef, decoder->module_) ||
935-
IsSubtypeOf(type, kWasmExnRef, decoder->module_)
934+
IsSubtypeOf(type, kWasmExternRef, decoder->module_)
936935
? LiftoffRegister(null_ref_reg)
937936
: LiftoffRegister(wasm_null_ref_reg),
938937
type.kind());
@@ -1668,7 +1667,7 @@ class LiftoffCompiler {
16681667
void ThrowRef(FullDecoder* decoder, Value*) {
16691668
// Like Rethrow, but pops the exception from the stack.
16701669
VarState exn = __ PopVarState();
1671-
CallBuiltin(Builtin::kWasmRethrow, MakeSig::Params(kRef), {exn},
1670+
CallBuiltin(Builtin::kWasmThrowRef, MakeSig::Params(kRef), {exn},
16721671
decoder->position());
16731672
int pc_offset = __ pc_offset();
16741673
MaybeOSR();
@@ -2622,8 +2621,7 @@ class LiftoffCompiler {
26222621
LiftoffRegister obj = pinned.set(__ PopToRegister(pinned));
26232622
if (null_check_strategy_ == compiler::NullCheckStrategy::kExplicit ||
26242623
IsSubtypeOf(kWasmI31Ref.AsNonNull(), arg.type, decoder->module_) ||
2625-
IsSubtypeOf(arg.type, kWasmExternRef, decoder->module_) ||
2626-
IsSubtypeOf(arg.type, kWasmExnRef, decoder->module_)) {
2624+
IsSubtypeOf(arg.type, kWasmExternRef, decoder->module_)) {
26272625
// Use an explicit null check if
26282626
// (1) we cannot use trap handler or
26292627
// (2) the object might be a Smi or
@@ -8253,11 +8251,9 @@ class LiftoffCompiler {
82538251
}
82548252

82558253
void LoadNullValue(Register null, ValueType type) {
8256-
// TODO(thibaudm): Can we use wasm null for exnref?
82578254
__ LoadFullPointer(
82588255
null, kRootRegister,
8259-
type == kWasmExternRef || type == kWasmNullExternRef ||
8260-
type == kWasmExnRef || type == kWasmNullExnRef
8256+
type == kWasmExternRef || type == kWasmNullExternRef
82618257
? IsolateData::root_slot_offset(RootIndex::kNullValue)
82628258
: IsolateData::root_slot_offset(RootIndex::kWasmNull));
82638259
}
@@ -8270,8 +8266,7 @@ class LiftoffCompiler {
82708266
ValueType type) {
82718267
#if V8_STATIC_ROOTS_BOOL
82728268
// TODO(14616): Extend this for shared types.
8273-
bool is_wasm_null = type != kWasmExternRef && type != kWasmNullExternRef &&
8274-
type != kWasmExnRef && type != kWasmNullExnRef;
8269+
bool is_wasm_null = type != kWasmExternRef && type != kWasmNullExternRef;
82758270
uint32_t value = is_wasm_null ? StaticReadOnlyRoot::kWasmNull
82768271
: StaticReadOnlyRoot::kNullValue;
82778272
__ 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/constant-expression.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ ValueOrError EvaluateConstantExpression(
3636
return WasmValue(expr.i32_value());
3737
case ConstantExpression::kRefNull:
3838
return WasmValue(
39-
expected == kWasmExternRef || expected == kWasmNullExternRef ||
40-
expected == kWasmNullExnRef || expected == kWasmExnRef
39+
expected == kWasmExternRef || expected == kWasmNullExternRef
4140
? Handle<Object>::cast(isolate->factory()->null_value())
4241
: Handle<Object>::cast(isolate->factory()->wasm_null()),
4342
ValueType::RefNull(expr.repr()));

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
};

0 commit comments

Comments
 (0)