Commit c7272fdd authored by Yuki Shiino's avatar Yuki Shiino Committed by Commit Bot

bind-gen: Fix FrozenArray support about setting integrity level

Makes "set integrity level to frozen" work on arbitrary v8::Value.
This patch supports |FrozenArray<T>?|, which is not always
a v8::Object.

Bug: 839389
Change-Id: I80f306d9f376a1e3b2d8562703273d610aca8257
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2136568Reviewed-by: default avatarHitoshi Yoshida <peria@chromium.org>
Commit-Queue: Yuki Shiino <yukishiino@chromium.org>
Cr-Commit-Position: refs/heads/master@{#756590}
parent 851b93f9
......@@ -1432,9 +1432,11 @@ def make_v8_set_return_value(cg_context):
return T("bindings::V8SetReturnValue({});".format(", ".join(args)))
if return_type.is_frozen_array:
return T("bindings::V8SetReturnValue(${info}, FreezeV8Object(ToV8("
"${return_value}, ${creation_context_object}, ${isolate}), "
"${isolate}));")
return T(
"bindings::V8SetReturnValue("
"${info}, "
"ToV8(${return_value}, ${creation_context_object}, ${isolate}), "
"bindings::V8ReturnValue::kFrozen);")
if return_type.is_promise:
return T("bindings::V8SetReturnValue"
......
......@@ -32,6 +32,9 @@ struct V8ReturnValue {
enum NonNullable { kNonNullable };
enum Nullable { kNullable };
// FrozenArray or not (the integrity level = frozen or not)
enum Frozen { kFrozen };
// Main world or not
enum MainWorld { kMainWorld };
......@@ -41,12 +44,22 @@ struct V8ReturnValue {
// V8 handle types
template <typename CallbackInfo, typename S>
void V8SetReturnValue(const CallbackInfo& info, const v8::Global<S> value) {
void V8SetReturnValue(const CallbackInfo& info, const v8::Local<S> value) {
info.GetReturnValue().Set(value);
}
template <typename CallbackInfo, typename S>
void V8SetReturnValue(const CallbackInfo& info, const v8::Local<S> value) {
void V8SetReturnValue(const CallbackInfo& info,
const v8::Local<S> value,
V8ReturnValue::Frozen) {
if (value->IsObject()) {
bool result =
value.template As<v8::Object>()
->SetIntegrityLevel(info.GetIsolate()->GetCurrentContext(),
v8::IntegrityLevel::kFrozen)
.ToChecked();
CHECK(result);
}
info.GetReturnValue().Set(value);
}
......
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