Skip to content

Commit f473f10

Browse files
jakobkummerowV8 LUCI CQ
authored andcommitted
[wasm] Refine installation of the WebAssembly.Tag constructor
This makes the installation sequence of WebAssembly.Tag slightly shorter, slightly faster, slightly cleaner in corner-case semantics, and slightly better documented. To allow testing this code, Isolate::InstallConditionalFeatures is exposed as d8.test.installConditionalFeatures(). Fixed: chromium:1314616 Change-Id: I44285e398b8797e0e7d2d8c782cecec3ba68a503 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3582382 Commit-Queue: Jakob Kummerow <[email protected]> Reviewed-by: Clemens Backes <[email protected]> Reviewed-by: Toon Verwaest <[email protected]> Cr-Commit-Position: refs/heads/main@{#79956}
1 parent 39f419f commit f473f10

File tree

3 files changed

+33
-19
lines changed

3 files changed

+33
-19
lines changed

src/d8/d8.cc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2183,6 +2183,12 @@ void Shell::TestVerifySourcePositions(
21832183
}
21842184
}
21852185

2186+
void Shell::InstallConditionalFeatures(
2187+
const v8::FunctionCallbackInfo<v8::Value>& args) {
2188+
Isolate* isolate = args.GetIsolate();
2189+
isolate->InstallConditionalFeatures(isolate->GetCurrentContext());
2190+
}
2191+
21862192
// async_hooks.createHook() registers functions to be called for different
21872193
// lifetime events of each async operation.
21882194
void Shell::AsyncHooksCreateHook(
@@ -3140,6 +3146,11 @@ Local<ObjectTemplate> Shell::CreateD8Template(Isolate* isolate) {
31403146
test_template->Set(isolate, "LeafInterfaceType",
31413147
Shell::CreateLeafInterfaceTypeTemplate(isolate));
31423148
}
3149+
// Allows testing code paths that are triggered when Origin Trials are
3150+
// added in the browser.
3151+
test_template->Set(
3152+
isolate, "installConditionalFeatures",
3153+
FunctionTemplate::New(isolate, Shell::InstallConditionalFeatures));
31433154

31443155
d8_template->Set(isolate, "test", test_template);
31453156
}

src/d8/d8.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,9 @@ class Shell : public i::AllStatic {
557557
static void TestVerifySourcePositions(
558558
const v8::FunctionCallbackInfo<v8::Value>& args);
559559

560+
static void InstallConditionalFeatures(
561+
const v8::FunctionCallbackInfo<v8::Value>& args);
562+
560563
static void AsyncHooksCreateHook(
561564
const v8::FunctionCallbackInfo<v8::Value>& args);
562565
static void AsyncHooksExecutionAsyncId(

src/wasm/wasm-js.cc

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2992,23 +2992,25 @@ void WasmJs::InstallConditionalFeatures(Isolate* isolate,
29922992
MaybeHandle<Object> maybe_webassembly =
29932993
JSObject::GetProperty(isolate, global, "WebAssembly");
29942994
Handle<Object> webassembly_obj;
2995-
if (!maybe_webassembly.ToHandle(&webassembly_obj)) {
2996-
// There is not {WebAssembly} object. We just return without adding the
2997-
// {Tag} constructor.
2998-
return;
2999-
}
3000-
if (!webassembly_obj->IsJSObject()) {
3001-
// The {WebAssembly} object is invalid. As we cannot add the {Tag}
3002-
// constructor, we just return.
2995+
if (!maybe_webassembly.ToHandle(&webassembly_obj) ||
2996+
!webassembly_obj->IsJSObject()) {
2997+
// There is no {WebAssembly} object, or it's not what we expect.
2998+
// Just return without adding the {Tag} constructor.
30032999
return;
30043000
}
30053001
Handle<JSObject> webassembly = Handle<JSObject>::cast(webassembly_obj);
3006-
// Setup Exception
3002+
// Setup Tag.
30073003
Handle<String> tag_name = v8_str(isolate, "Tag");
3004+
// The {WebAssembly} object may already have been modified. The following
3005+
// code is designed to:
3006+
// - check for existing {Tag} properties on the object itself, and avoid
3007+
// overwriting them or adding duplicate properties
3008+
// - disregard any setters or read-only properties on the prototype chain
3009+
// - only make objects accessible to user code after all internal setup
3010+
// has been completed.
30083011
if (JSObject::HasOwnProperty(isolate, webassembly, tag_name)
30093012
.FromMaybe(true)) {
3010-
// The {Exception} constructor already exists, there is nothing more to
3011-
// do.
3013+
// Existing property, or exception.
30123014
return;
30133015
}
30143016

@@ -3017,21 +3019,19 @@ void WasmJs::InstallConditionalFeatures(Isolate* isolate,
30173019
CreateFunc(isolate, tag_name, WebAssemblyTag, has_prototype,
30183020
SideEffectType::kHasNoSideEffect);
30193021
tag_constructor->shared().set_length(1);
3020-
auto result =
3021-
Object::SetProperty(isolate, webassembly, tag_name, tag_constructor,
3022-
StoreOrigin::kNamed, Just(ShouldThrow::kDontThrow));
3023-
if (result.is_null()) {
3024-
// Setting the {Tag} constructor failed. We just bail out.
3025-
return;
3026-
}
3027-
// Install the constructor on the context.
30283022
context->set_wasm_tag_constructor(*tag_constructor);
30293023
Handle<JSObject> tag_proto =
30303024
SetupConstructor(isolate, tag_constructor, i::WASM_TAG_OBJECT_TYPE,
30313025
WasmTagObject::kHeaderSize, "WebAssembly.Tag");
30323026
if (enabled_features.has_type_reflection()) {
30333027
InstallFunc(isolate, tag_proto, "type", WebAssemblyTagType, 0);
30343028
}
3029+
LookupIterator it(isolate, webassembly, tag_name, LookupIterator::OWN);
3030+
Maybe<bool> result = JSObject::DefineOwnPropertyIgnoreAttributes(
3031+
&it, tag_constructor, DONT_ENUM, Just(kDontThrow));
3032+
// This could still fail if the object was non-extensible, but now we
3033+
// return anyway so there's no need to even check.
3034+
USE(result);
30353035
}
30363036
}
30373037
#undef ASSIGN

0 commit comments

Comments
 (0)