Commit 96854911 authored by Andreas Haas's avatar Andreas Haas Committed by V8 LUCI CQ

[wasm] Set correct prototype for WebAssembly.Global

This fixes the first part of a failing spec test, the other WebAssembly
objects will follow in other CLs.

R=jkummerow@chromium.org

Bug: v8:12227
Change-Id: I7b57b0c518671f0614a88f0477b64e2507435aba
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3168272
Commit-Queue: Andreas Haas <ahaas@chromium.org>
Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
Cr-Commit-Position: refs/heads/main@{#76907}
parent 656b1d64
......@@ -1362,6 +1362,26 @@ void WebAssemblyGlobal(const v8::FunctionCallbackInfo<v8::Value>& args) {
return;
}
// The infrastructure for `new Foo` calls allocates an object, which is
// available here as {args.This()}. We're going to discard this object
// and use {global_obj} instead, but it does have the correct prototype,
// which we must harvest from it. This makes a difference when the JS
// constructor function wasn't {WebAssembly.Global} directly, but some
// subclass: {global_obj} has {WebAssembly.Global}'s prototype at this
// point, so we must overwrite that with the correct prototype for {Foo}.
i::MaybeHandle<i::HeapObject> maybe_prototype =
i::JSObject::GetPrototype(i_isolate, Utils::OpenHandle(*args.This()));
i::Handle<i::HeapObject> prototype;
if (maybe_prototype.ToHandle(&prototype)) {
Maybe<bool> result = i::JSObject::SetPrototype(global_obj, prototype,
/*from_javascript=*/false,
internal::kThrowOnError);
if (!result.FromJust()) {
DCHECK(i_isolate->has_pending_exception());
return;
}
}
// Convert value to a WebAssembly value, the default value is 0.
Local<v8::Value> value = Local<Value>::Cast(args[1]);
switch (type.kind()) {
......
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
(function GlobalPrototype() {
class _Global extends WebAssembly.Global {}
let global = new _Global({value: 'i32', mutable: false}, 0);
assertInstanceof(global, _Global);
assertInstanceof(global, WebAssembly.Global);
})();
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment