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

bind-gen: Implement V8SetReturnValue for exposed interface objects

Bug: 839389
Change-Id: I837036ea6e9d0e0fb52abb6d6c56d3f41947a06d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2074997Reviewed-by: default avatarHitoshi Yoshida <peria@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Commit-Queue: Yuki Shiino <yukishiino@chromium.org>
Cr-Commit-Position: refs/heads/master@{#744918}
parent 2f36c713
...@@ -116,16 +116,16 @@ typename IDLSequence<T>::ImplType VariadicArgumentsToNativeValues( ...@@ -116,16 +116,16 @@ typename IDLSequence<T>::ImplType VariadicArgumentsToNativeValues(
return std::move(result); return std::move(result);
} }
base::Optional<size_t> FindIndexInEnumStringTable( CORE_EXPORT base::Optional<size_t> FindIndexInEnumStringTable(
v8::Isolate* isolate, v8::Isolate* isolate,
v8::Local<v8::Value> value, v8::Local<v8::Value> value,
base::span<const char* const> enum_value_table, base::span<const char* const> enum_value_table,
const char* enum_type_name, const char* enum_type_name,
ExceptionState& exception_state); ExceptionState& exception_state);
bool IsEsIterableObject(v8::Isolate* isolate, CORE_EXPORT bool IsEsIterableObject(v8::Isolate* isolate,
v8::Local<v8::Value> value, v8::Local<v8::Value> value,
ExceptionState& exception_state); ExceptionState& exception_state);
} // namespace bindings } // namespace bindings
......
...@@ -1593,7 +1593,8 @@ def make_exposed_construct_callback_def(cg_context, function_name): ...@@ -1593,7 +1593,8 @@ def make_exposed_construct_callback_def(cg_context, function_name):
v8_set_return_value = _format( v8_set_return_value = _format(
"bindings::V8SetReturnValue" "bindings::V8SetReturnValue"
"(${info}, {}::GetWrapperTypeInfo(), InterfaceObject);", "(${info}, {}::GetWrapperTypeInfo(), "
"bindings::V8ReturnValue::kInterfaceObject);",
v8_bridge_class_name(cg_context.exposed_construct)) v8_bridge_class_name(cg_context.exposed_construct))
body.extend([ body.extend([
make_runtime_call_timer_scope(cg_context), make_runtime_call_timer_scope(cg_context),
......
...@@ -458,6 +458,7 @@ jumbo_component("platform") { ...@@ -458,6 +458,7 @@ jumbo_component("platform") {
"bindings/v8_per_isolate_data.h", "bindings/v8_per_isolate_data.h",
"bindings/v8_private_property.cc", "bindings/v8_private_property.cc",
"bindings/v8_private_property.h", "bindings/v8_private_property.h",
"bindings/v8_set_return_value.cc",
"bindings/v8_set_return_value.h", "bindings/v8_set_return_value.h",
"bindings/v8_throw_exception.cc", "bindings/v8_throw_exception.cc",
"bindings/v8_throw_exception.h", "bindings/v8_throw_exception.h",
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "third_party/blink/renderer/platform/bindings/v8_set_return_value.h"
#include "third_party/blink/renderer/platform/bindings/runtime_call_stats.h"
#include "third_party/blink/renderer/platform/bindings/v8_per_context_data.h"
namespace blink {
namespace bindings {
v8::Local<v8::Value> GetInterfaceObjectExposedOnGlobal(
v8::Isolate* isolate,
v8::Local<v8::Object> creation_context,
const WrapperTypeInfo* wrapper_type_info) {
RUNTIME_CALL_TIMER_SCOPE_DISABLED_BY_DEFAULT(
isolate, "Blink_GetInterfaceObjectExposedOnGlobal");
V8PerContextData* per_context_data =
V8PerContextData::From(creation_context->CreationContext());
if (!per_context_data)
return v8::Local<v8::Value>();
return per_context_data->ConstructorForType(wrapper_type_info);
}
} // namespace bindings
} // namespace blink
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "third_party/blink/renderer/platform/bindings/script_wrappable.h" #include "third_party/blink/renderer/platform/bindings/script_wrappable.h"
#include "third_party/blink/renderer/platform/bindings/v8_per_isolate_data.h" #include "third_party/blink/renderer/platform/bindings/v8_per_isolate_data.h"
#include "third_party/blink/renderer/platform/bindings/v8_value_cache.h" #include "third_party/blink/renderer/platform/bindings/v8_value_cache.h"
#include "third_party/blink/renderer/platform/platform_export.h"
#include "v8/include/v8.h" #include "v8/include/v8.h"
namespace blink { namespace blink {
...@@ -32,6 +33,9 @@ struct V8ReturnValue { ...@@ -32,6 +33,9 @@ struct V8ReturnValue {
// Main world or not // Main world or not
enum MainWorld { kMainWorld }; enum MainWorld { kMainWorld };
// Returns the interface object of the given type.
enum InterfaceObject { kInterfaceObject };
}; };
// V8 handle types // V8 handle types
...@@ -237,6 +241,20 @@ void V8SetReturnValue(const CallbackInfo& info, ...@@ -237,6 +241,20 @@ void V8SetReturnValue(const CallbackInfo& info,
wrappable->Wrap(info.GetIsolate(), creation_context->Global())); wrappable->Wrap(info.GetIsolate(), creation_context->Global()));
} }
// Interface object
PLATFORM_EXPORT v8::Local<v8::Value> GetInterfaceObjectExposedOnGlobal(
v8::Isolate* isolate,
v8::Local<v8::Object> creation_context,
const WrapperTypeInfo* wrapper_type_info);
template <typename CallbackInfo>
void V8SetReturnValue(const CallbackInfo& info,
const WrapperTypeInfo* wrapper_type_info,
V8ReturnValue::InterfaceObject) {
info.GetReturnValue().Set(GetInterfaceObjectExposedOnGlobal(
info.GetIsolate(), info.This(), wrapper_type_info));
}
// Nullable types // Nullable types
template <typename CallbackInfo, typename T> template <typename CallbackInfo, typename T>
void V8SetReturnValue(const CallbackInfo& info, base::Optional<T> value) { void V8SetReturnValue(const CallbackInfo& info, base::Optional<T> 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