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

bind-gen: Make generated interface compilable (2 of N)

- Add IDLObject
- Add V8T::HasInstance

Bug: 839389
Change-Id: I08edcb3428e31a74d546ab8e11c0da2e549a9fe2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2000395Reviewed-by: default avatarHitoshi Yoshida <peria@chromium.org>
Commit-Queue: Yuki Shiino <yukishiino@chromium.org>
Cr-Commit-Position: refs/heads/master@{#731953}
parent 5cb2e8b8
......@@ -20,6 +20,7 @@ namespace blink {
class EventListener;
class ScriptPromise;
class ScriptValue;
// Boolean
struct IDLBoolean final : public IDLBaseHelper<bool> {};
......@@ -131,6 +132,9 @@ struct IDLUnrestrictedFloat final : public IDLBaseHelper<float> {};
struct IDLDateOrNull final : public IDLBaseHelper<base::Optional<base::Time>> {
};
// object
struct IDLObject final : public IDLBaseHelper<ScriptValue> {};
// Promise
struct IDLPromise final : public IDLBaseHelper<ScriptPromise> {};
......
......@@ -9,10 +9,12 @@
#include "third_party/blink/renderer/bindings/core/v8/native_value_traits.h"
#include "third_party/blink/renderer/bindings/core/v8/script_iterator.h"
#include "third_party/blink/renderer/bindings/core/v8/script_promise.h"
#include "third_party/blink/renderer/bindings/core/v8/script_value.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_binding_for_core.h"
#include "third_party/blink/renderer/core/core_export.h"
#include "third_party/blink/renderer/core/typed_arrays/dom_data_view.h"
#include "third_party/blink/renderer/core/typed_arrays/dom_typed_array.h"
#include "third_party/blink/renderer/platform/bindings/exception_messages.h"
#include "third_party/blink/renderer/platform/wtf/text/wtf_string.h"
namespace blink {
......@@ -569,18 +571,6 @@ DEFINE_NATIVE_VALUE_TRAITS_BUFFER_SOURCE_TYPE(DOMFloat64Array);
DEFINE_NATIVE_VALUE_TRAITS_BUFFER_SOURCE_TYPE(DOMDataView);
#undef DEFINE_NATIVE_VALUE_TRAITS_BUFFER_SOURCE_TYPE
// Promises
template <>
struct CORE_EXPORT NativeValueTraits<IDLPromise>
: public NativeValueTraitsBase<IDLPromise> {
static ScriptPromise NativeValue(v8::Isolate* isolate,
v8::Local<v8::Value> value,
ExceptionState& exception_state) {
return ScriptPromise::Cast(ScriptState::From(isolate->GetCurrentContext()),
value);
}
};
// Nullable Date
template <>
struct CORE_EXPORT NativeValueTraits<IDLDateOrNull>
......@@ -593,6 +583,46 @@ struct CORE_EXPORT NativeValueTraits<IDLDateOrNull>
}
};
// object
template <>
struct CORE_EXPORT NativeValueTraits<IDLObject>
: public NativeValueTraitsBase<IDLObject> {
static ScriptValue NativeValue(v8::Isolate* isolate,
v8::Local<v8::Value> value,
ExceptionState& exception_state) {
if (value->IsObject())
return ScriptValue(isolate, value);
exception_state.ThrowTypeError(
ExceptionMessages::FailedToConvertJSValue("object"));
return ScriptValue();
}
static ScriptValue ArgumentValue(v8::Isolate* isolate,
int argument_index,
v8::Local<v8::Value> value,
ExceptionState& exception_state) {
if (value->IsObject())
return ScriptValue(isolate, value);
exception_state.ThrowTypeError(
ExceptionMessages::ArgumentNotOfType(argument_index, "object"));
return ScriptValue();
}
static ScriptValue NullValue() { return ScriptValue(); }
};
// Promises
template <>
struct CORE_EXPORT NativeValueTraits<IDLPromise>
: public NativeValueTraitsBase<IDLPromise> {
static ScriptPromise NativeValue(v8::Isolate* isolate,
v8::Local<v8::Value> value,
ExceptionState& exception_state) {
return ScriptPromise::Cast(ScriptState::From(isolate->GetCurrentContext()),
value);
}
};
// Sequences
template <typename T>
struct NativeValueTraits<IDLSequence<T>>
......
......@@ -183,8 +183,8 @@ def native_value_tag(idl_type):
real_type = idl_type.unwrap(typedef=True)
non_null_real_type = real_type.unwrap(nullable=True)
if (real_type.is_boolean or real_type.is_numeric
or non_null_real_type.is_any or non_null_real_type.is_object):
if (real_type.is_boolean or real_type.is_numeric or real_type.is_any
or real_type.is_object):
return "IDL{}".format(real_type.type_name)
if non_null_real_type.is_string:
......
......@@ -155,7 +155,6 @@ def collect_include_headers(idl_definition):
continue
if isinstance(type_def_obj, web_idl.Dictionary):
header_paths.add(PathManager(type_def_obj).dict_path(ext="h"))
continue
header_paths.add(PathManager(type_def_obj).api_path(ext="h"))
return header_paths
......
......@@ -609,7 +609,7 @@ def make_check_receiver(cg_context):
return SequenceNode([
T("// [LenientThis]"),
CxxUnlikelyIfNode(
cond="!${class_name}::HasInstance(${v8_receiver}, ${isolate})",
cond="!${class_name}::HasInstance(${isolate}, ${v8_receiver})",
body=T("return;")),
])
......@@ -618,7 +618,7 @@ def make_check_receiver(cg_context):
T("// Promise returning function: "
"Convert a TypeError to a reject promise."),
CxxUnlikelyIfNode(
cond="!${class_name}::HasInstance(${v8_receiver}, ${isolate})",
cond="!${class_name}::HasInstance(${isolate}, ${v8_receiver})",
body=[
T("${exception_state}.ThrowTypeError("
"\"Illegal invocation\");"),
......
......@@ -6,6 +6,7 @@
#define THIRD_PARTY_BLINK_RENDERER_PLATFORM_BINDINGS_V8_INTERFACE_BRIDGE_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/wrapper_type_info.h"
#include "third_party/blink/renderer/platform/platform_export.h"
#include "third_party/blink/renderer/platform/wtf/allocator/allocator.h"
......@@ -54,7 +55,16 @@ class V8InterfaceBridge : public V8InterfaceBridgeBase {
return ToScriptWrappable(receiver)->ToImpl<T>();
}
static bool HasInstance(v8::Isolate* isolate, v8::Local<v8::Value> value) {
return V8PerIsolateData::From(isolate)->HasInstance(
V8T::GetWrapperTypeInfo(), value);
}
// Migration adapter
static bool HasInstance(v8::Local<v8::Value> value, v8::Isolate* isolate) {
return HasInstance(isolate, value);
}
static void InstallContextDependentAdapter(
v8::Local<v8::Context> context,
const DOMWrapperWorld& world,
......
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