Commit 8fceeae0 authored by Yuki Shiino's avatar Yuki Shiino Committed by Commit Bot

bind-gen: Implement NativeValueTraits for interface

Makes NativeValueTraits work well with the new generated
code of IDL interface.

Adds NativeValueTraits::ArgumentValue in addition to
NativeValue in order to produce better error messages.

Bug: 839389
Change-Id: I050dfa5b53c11aea6e50de5ef0148292db7fb3cb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1995241
Commit-Queue: Yuki Shiino <yukishiino@chromium.org>
Reviewed-by: default avatarHitoshi Yoshida <peria@chromium.org>
Cr-Commit-Position: refs/heads/master@{#731179}
parent c320bef9
...@@ -37,6 +37,20 @@ ScriptWrappable* NativeValueTraitsInterfaceNativeValue( ...@@ -37,6 +37,20 @@ ScriptWrappable* NativeValueTraitsInterfaceNativeValue(
return ToScriptWrappable(value.As<v8::Object>()); return ToScriptWrappable(value.As<v8::Object>());
} }
ScriptWrappable* NativeValueTraitsInterfaceArgumentValue(
v8::Isolate* isolate,
const WrapperTypeInfo* wrapper_type_info,
int argument_index,
v8::Local<v8::Value> value,
ExceptionState& exception_state) {
if (!V8PerIsolateData::From(isolate)->HasInstance(wrapper_type_info, value)) {
exception_state.ThrowTypeError(ExceptionMessages::ArgumentNotOfType(
argument_index, wrapper_type_info->interface_name));
return nullptr;
}
return ToScriptWrappable(value.As<v8::Object>());
}
} // namespace bindings } // namespace bindings
#define DEFINE_NATIVE_VALUE_TRAITS_BUFFER_SOURCE_TYPE(T, V8T) \ #define DEFINE_NATIVE_VALUE_TRAITS_BUFFER_SOURCE_TYPE(T, V8T) \
......
...@@ -31,6 +31,13 @@ CORE_EXPORT ScriptWrappable* NativeValueTraitsInterfaceNativeValue( ...@@ -31,6 +31,13 @@ CORE_EXPORT ScriptWrappable* NativeValueTraitsInterfaceNativeValue(
v8::Local<v8::Value> value, v8::Local<v8::Value> value,
ExceptionState& exception_state); ExceptionState& exception_state);
CORE_EXPORT ScriptWrappable* NativeValueTraitsInterfaceArgumentValue(
v8::Isolate* isolate,
const WrapperTypeInfo* wrapper_type_info,
int argument_index,
v8::Local<v8::Value> value,
ExceptionState& exception_state);
} // namespace bindings } // namespace bindings
// Boolean // Boolean
...@@ -42,6 +49,13 @@ struct CORE_EXPORT NativeValueTraits<IDLBoolean> ...@@ -42,6 +49,13 @@ struct CORE_EXPORT NativeValueTraits<IDLBoolean>
ExceptionState& exception_state) { ExceptionState& exception_state) {
return ToBoolean(isolate, value, exception_state); return ToBoolean(isolate, value, exception_state);
} }
static bool ArgumentValue(v8::Isolate* isolate,
int argument_index,
v8::Local<v8::Value> value,
ExceptionState& exception_state) {
return NativeValue(isolate, value, exception_state);
}
}; };
// Integers // Integers
...@@ -53,6 +67,13 @@ struct CORE_EXPORT NativeValueTraits<IDLByte> ...@@ -53,6 +67,13 @@ struct CORE_EXPORT NativeValueTraits<IDLByte>
ExceptionState& exception_state) { ExceptionState& exception_state) {
return ToInt8(isolate, value, kNormalConversion, exception_state); return ToInt8(isolate, value, kNormalConversion, exception_state);
} }
static int8_t ArgumentValue(v8::Isolate* isolate,
int argument_index,
v8::Local<v8::Value> value,
ExceptionState& exception_state) {
return NativeValue(isolate, value, exception_state);
}
}; };
template <> template <>
...@@ -63,6 +84,13 @@ struct CORE_EXPORT NativeValueTraits<IDLOctet> ...@@ -63,6 +84,13 @@ struct CORE_EXPORT NativeValueTraits<IDLOctet>
ExceptionState& exception_state) { ExceptionState& exception_state) {
return ToUInt8(isolate, value, kNormalConversion, exception_state); return ToUInt8(isolate, value, kNormalConversion, exception_state);
} }
static uint8_t ArgumentValue(v8::Isolate* isolate,
int argument_index,
v8::Local<v8::Value> value,
ExceptionState& exception_state) {
return NativeValue(isolate, value, exception_state);
}
}; };
template <> template <>
...@@ -73,6 +101,13 @@ struct CORE_EXPORT NativeValueTraits<IDLShort> ...@@ -73,6 +101,13 @@ struct CORE_EXPORT NativeValueTraits<IDLShort>
ExceptionState& exception_state) { ExceptionState& exception_state) {
return ToInt16(isolate, value, kNormalConversion, exception_state); return ToInt16(isolate, value, kNormalConversion, exception_state);
} }
static int16_t ArgumentValue(v8::Isolate* isolate,
int argument_index,
v8::Local<v8::Value> value,
ExceptionState& exception_state) {
return NativeValue(isolate, value, exception_state);
}
}; };
template <> template <>
...@@ -83,6 +118,13 @@ struct CORE_EXPORT NativeValueTraits<IDLUnsignedShort> ...@@ -83,6 +118,13 @@ struct CORE_EXPORT NativeValueTraits<IDLUnsignedShort>
ExceptionState& exception_state) { ExceptionState& exception_state) {
return ToUInt16(isolate, value, kNormalConversion, exception_state); return ToUInt16(isolate, value, kNormalConversion, exception_state);
} }
static uint16_t ArgumentValue(v8::Isolate* isolate,
int argument_index,
v8::Local<v8::Value> value,
ExceptionState& exception_state) {
return NativeValue(isolate, value, exception_state);
}
}; };
template <> template <>
...@@ -93,6 +135,13 @@ struct CORE_EXPORT NativeValueTraits<IDLLong> ...@@ -93,6 +135,13 @@ struct CORE_EXPORT NativeValueTraits<IDLLong>
ExceptionState& exception_state) { ExceptionState& exception_state) {
return ToInt32(isolate, value, kNormalConversion, exception_state); return ToInt32(isolate, value, kNormalConversion, exception_state);
} }
static int32_t ArgumentValue(v8::Isolate* isolate,
int argument_index,
v8::Local<v8::Value> value,
ExceptionState& exception_state) {
return NativeValue(isolate, value, exception_state);
}
}; };
template <> template <>
...@@ -103,6 +152,13 @@ struct CORE_EXPORT NativeValueTraits<IDLUnsignedLong> ...@@ -103,6 +152,13 @@ struct CORE_EXPORT NativeValueTraits<IDLUnsignedLong>
ExceptionState& exception_state) { ExceptionState& exception_state) {
return ToUInt32(isolate, value, kNormalConversion, exception_state); return ToUInt32(isolate, value, kNormalConversion, exception_state);
} }
static uint32_t ArgumentValue(v8::Isolate* isolate,
int argument_index,
v8::Local<v8::Value> value,
ExceptionState& exception_state) {
return NativeValue(isolate, value, exception_state);
}
}; };
template <> template <>
...@@ -113,6 +169,13 @@ struct CORE_EXPORT NativeValueTraits<IDLLongLong> ...@@ -113,6 +169,13 @@ struct CORE_EXPORT NativeValueTraits<IDLLongLong>
ExceptionState& exception_state) { ExceptionState& exception_state) {
return ToInt64(isolate, value, kNormalConversion, exception_state); return ToInt64(isolate, value, kNormalConversion, exception_state);
} }
static int64_t ArgumentValue(v8::Isolate* isolate,
int argument_index,
v8::Local<v8::Value> value,
ExceptionState& exception_state) {
return NativeValue(isolate, value, exception_state);
}
}; };
template <> template <>
...@@ -123,6 +186,13 @@ struct CORE_EXPORT NativeValueTraits<IDLUnsignedLongLong> ...@@ -123,6 +186,13 @@ struct CORE_EXPORT NativeValueTraits<IDLUnsignedLongLong>
ExceptionState& exception_state) { ExceptionState& exception_state) {
return ToUInt64(isolate, value, kNormalConversion, exception_state); return ToUInt64(isolate, value, kNormalConversion, exception_state);
} }
static uint64_t ArgumentValue(v8::Isolate* isolate,
int argument_index,
v8::Local<v8::Value> value,
ExceptionState& exception_state) {
return NativeValue(isolate, value, exception_state);
}
}; };
// [Clamp] Integers // [Clamp] Integers
...@@ -134,6 +204,13 @@ struct CORE_EXPORT NativeValueTraits<IDLByteClamp> ...@@ -134,6 +204,13 @@ struct CORE_EXPORT NativeValueTraits<IDLByteClamp>
ExceptionState& exception_state) { ExceptionState& exception_state) {
return ToInt8(isolate, value, kClamp, exception_state); return ToInt8(isolate, value, kClamp, exception_state);
} }
static int8_t ArgumentValue(v8::Isolate* isolate,
int argument_index,
v8::Local<v8::Value> value,
ExceptionState& exception_state) {
return NativeValue(isolate, value, exception_state);
}
}; };
template <> template <>
...@@ -144,6 +221,13 @@ struct CORE_EXPORT NativeValueTraits<IDLOctetClamp> ...@@ -144,6 +221,13 @@ struct CORE_EXPORT NativeValueTraits<IDLOctetClamp>
ExceptionState& exception_state) { ExceptionState& exception_state) {
return ToUInt8(isolate, value, kClamp, exception_state); return ToUInt8(isolate, value, kClamp, exception_state);
} }
static uint8_t ArgumentValue(v8::Isolate* isolate,
int argument_index,
v8::Local<v8::Value> value,
ExceptionState& exception_state) {
return NativeValue(isolate, value, exception_state);
}
}; };
template <> template <>
...@@ -154,6 +238,13 @@ struct CORE_EXPORT NativeValueTraits<IDLShortClamp> ...@@ -154,6 +238,13 @@ struct CORE_EXPORT NativeValueTraits<IDLShortClamp>
ExceptionState& exception_state) { ExceptionState& exception_state) {
return ToInt16(isolate, value, kClamp, exception_state); return ToInt16(isolate, value, kClamp, exception_state);
} }
static int16_t ArgumentValue(v8::Isolate* isolate,
int argument_index,
v8::Local<v8::Value> value,
ExceptionState& exception_state) {
return NativeValue(isolate, value, exception_state);
}
}; };
template <> template <>
...@@ -164,6 +255,13 @@ struct CORE_EXPORT NativeValueTraits<IDLUnsignedShortClamp> ...@@ -164,6 +255,13 @@ struct CORE_EXPORT NativeValueTraits<IDLUnsignedShortClamp>
ExceptionState& exception_state) { ExceptionState& exception_state) {
return ToUInt16(isolate, value, kClamp, exception_state); return ToUInt16(isolate, value, kClamp, exception_state);
} }
static uint16_t ArgumentValue(v8::Isolate* isolate,
int argument_index,
v8::Local<v8::Value> value,
ExceptionState& exception_state) {
return NativeValue(isolate, value, exception_state);
}
}; };
template <> template <>
...@@ -174,6 +272,13 @@ struct CORE_EXPORT NativeValueTraits<IDLLongClamp> ...@@ -174,6 +272,13 @@ struct CORE_EXPORT NativeValueTraits<IDLLongClamp>
ExceptionState& exception_state) { ExceptionState& exception_state) {
return ToInt32(isolate, value, kClamp, exception_state); return ToInt32(isolate, value, kClamp, exception_state);
} }
static int32_t ArgumentValue(v8::Isolate* isolate,
int argument_index,
v8::Local<v8::Value> value,
ExceptionState& exception_state) {
return NativeValue(isolate, value, exception_state);
}
}; };
template <> template <>
...@@ -184,6 +289,13 @@ struct CORE_EXPORT NativeValueTraits<IDLUnsignedLongClamp> ...@@ -184,6 +289,13 @@ struct CORE_EXPORT NativeValueTraits<IDLUnsignedLongClamp>
ExceptionState& exception_state) { ExceptionState& exception_state) {
return ToUInt32(isolate, value, kClamp, exception_state); return ToUInt32(isolate, value, kClamp, exception_state);
} }
static uint32_t ArgumentValue(v8::Isolate* isolate,
int argument_index,
v8::Local<v8::Value> value,
ExceptionState& exception_state) {
return NativeValue(isolate, value, exception_state);
}
}; };
template <> template <>
...@@ -194,6 +306,13 @@ struct CORE_EXPORT NativeValueTraits<IDLLongLongClamp> ...@@ -194,6 +306,13 @@ struct CORE_EXPORT NativeValueTraits<IDLLongLongClamp>
ExceptionState& exception_state) { ExceptionState& exception_state) {
return ToInt64(isolate, value, kClamp, exception_state); return ToInt64(isolate, value, kClamp, exception_state);
} }
static int64_t ArgumentValue(v8::Isolate* isolate,
int argument_index,
v8::Local<v8::Value> value,
ExceptionState& exception_state) {
return NativeValue(isolate, value, exception_state);
}
}; };
template <> template <>
...@@ -204,6 +323,13 @@ struct CORE_EXPORT NativeValueTraits<IDLUnsignedLongLongClamp> ...@@ -204,6 +323,13 @@ struct CORE_EXPORT NativeValueTraits<IDLUnsignedLongLongClamp>
ExceptionState& exception_state) { ExceptionState& exception_state) {
return ToUInt64(isolate, value, kClamp, exception_state); return ToUInt64(isolate, value, kClamp, exception_state);
} }
static uint64_t ArgumentValue(v8::Isolate* isolate,
int argument_index,
v8::Local<v8::Value> value,
ExceptionState& exception_state) {
return NativeValue(isolate, value, exception_state);
}
}; };
// [EnforceRange] Integers // [EnforceRange] Integers
...@@ -215,6 +341,13 @@ struct CORE_EXPORT NativeValueTraits<IDLByteEnforceRange> ...@@ -215,6 +341,13 @@ struct CORE_EXPORT NativeValueTraits<IDLByteEnforceRange>
ExceptionState& exception_state) { ExceptionState& exception_state) {
return ToInt8(isolate, value, kEnforceRange, exception_state); return ToInt8(isolate, value, kEnforceRange, exception_state);
} }
static int8_t ArgumentValue(v8::Isolate* isolate,
int argument_index,
v8::Local<v8::Value> value,
ExceptionState& exception_state) {
return NativeValue(isolate, value, exception_state);
}
}; };
template <> template <>
...@@ -225,6 +358,13 @@ struct CORE_EXPORT NativeValueTraits<IDLOctetEnforceRange> ...@@ -225,6 +358,13 @@ struct CORE_EXPORT NativeValueTraits<IDLOctetEnforceRange>
ExceptionState& exception_state) { ExceptionState& exception_state) {
return ToUInt8(isolate, value, kEnforceRange, exception_state); return ToUInt8(isolate, value, kEnforceRange, exception_state);
} }
static uint8_t ArgumentValue(v8::Isolate* isolate,
int argument_index,
v8::Local<v8::Value> value,
ExceptionState& exception_state) {
return NativeValue(isolate, value, exception_state);
}
}; };
template <> template <>
...@@ -235,6 +375,13 @@ struct CORE_EXPORT NativeValueTraits<IDLShortEnforceRange> ...@@ -235,6 +375,13 @@ struct CORE_EXPORT NativeValueTraits<IDLShortEnforceRange>
ExceptionState& exception_state) { ExceptionState& exception_state) {
return ToInt16(isolate, value, kEnforceRange, exception_state); return ToInt16(isolate, value, kEnforceRange, exception_state);
} }
static int16_t ArgumentValue(v8::Isolate* isolate,
int argument_index,
v8::Local<v8::Value> value,
ExceptionState& exception_state) {
return NativeValue(isolate, value, exception_state);
}
}; };
template <> template <>
...@@ -245,6 +392,13 @@ struct CORE_EXPORT NativeValueTraits<IDLUnsignedShortEnforceRange> ...@@ -245,6 +392,13 @@ struct CORE_EXPORT NativeValueTraits<IDLUnsignedShortEnforceRange>
ExceptionState& exception_state) { ExceptionState& exception_state) {
return ToUInt16(isolate, value, kEnforceRange, exception_state); return ToUInt16(isolate, value, kEnforceRange, exception_state);
} }
static uint16_t ArgumentValue(v8::Isolate* isolate,
int argument_index,
v8::Local<v8::Value> value,
ExceptionState& exception_state) {
return NativeValue(isolate, value, exception_state);
}
}; };
template <> template <>
...@@ -255,6 +409,13 @@ struct CORE_EXPORT NativeValueTraits<IDLLongEnforceRange> ...@@ -255,6 +409,13 @@ struct CORE_EXPORT NativeValueTraits<IDLLongEnforceRange>
ExceptionState& exception_state) { ExceptionState& exception_state) {
return ToInt32(isolate, value, kEnforceRange, exception_state); return ToInt32(isolate, value, kEnforceRange, exception_state);
} }
static int32_t ArgumentValue(v8::Isolate* isolate,
int argument_index,
v8::Local<v8::Value> value,
ExceptionState& exception_state) {
return NativeValue(isolate, value, exception_state);
}
}; };
template <> template <>
...@@ -265,6 +426,13 @@ struct CORE_EXPORT NativeValueTraits<IDLUnsignedLongEnforceRange> ...@@ -265,6 +426,13 @@ struct CORE_EXPORT NativeValueTraits<IDLUnsignedLongEnforceRange>
ExceptionState& exception_state) { ExceptionState& exception_state) {
return ToUInt32(isolate, value, kEnforceRange, exception_state); return ToUInt32(isolate, value, kEnforceRange, exception_state);
} }
static uint32_t ArgumentValue(v8::Isolate* isolate,
int argument_index,
v8::Local<v8::Value> value,
ExceptionState& exception_state) {
return NativeValue(isolate, value, exception_state);
}
}; };
template <> template <>
...@@ -275,6 +443,13 @@ struct CORE_EXPORT NativeValueTraits<IDLLongLongEnforceRange> ...@@ -275,6 +443,13 @@ struct CORE_EXPORT NativeValueTraits<IDLLongLongEnforceRange>
ExceptionState& exception_state) { ExceptionState& exception_state) {
return ToInt64(isolate, value, kEnforceRange, exception_state); return ToInt64(isolate, value, kEnforceRange, exception_state);
} }
static int64_t ArgumentValue(v8::Isolate* isolate,
int argument_index,
v8::Local<v8::Value> value,
ExceptionState& exception_state) {
return NativeValue(isolate, value, exception_state);
}
}; };
template <> template <>
...@@ -285,6 +460,13 @@ struct CORE_EXPORT NativeValueTraits<IDLUnsignedLongLongEnforceRange> ...@@ -285,6 +460,13 @@ struct CORE_EXPORT NativeValueTraits<IDLUnsignedLongLongEnforceRange>
ExceptionState& exception_state) { ExceptionState& exception_state) {
return ToUInt64(isolate, value, kEnforceRange, exception_state); return ToUInt64(isolate, value, kEnforceRange, exception_state);
} }
static uint64_t ArgumentValue(v8::Isolate* isolate,
int argument_index,
v8::Local<v8::Value> value,
ExceptionState& exception_state) {
return NativeValue(isolate, value, exception_state);
}
}; };
// Strings // Strings
...@@ -434,6 +616,18 @@ struct NativeValueTraits<IDLByteStringBaseV2<mode>> ...@@ -434,6 +616,18 @@ struct NativeValueTraits<IDLByteStringBaseV2<mode>>
} }
return bindings::NativeValueTraitsStringAdapter(v8_string); return bindings::NativeValueTraitsStringAdapter(v8_string);
} }
static bindings::NativeValueTraitsStringAdapter ArgumentValue(
v8::Isolate* isolate,
int argument_index,
v8::Local<v8::Value> value,
ExceptionState& exception_state) {
return NativeValue(isolate, value, exception_state);
}
static bindings::NativeValueTraitsStringAdapter NullValue() {
return bindings::NativeValueTraitsStringAdapter();
}
}; };
template <bindings::NativeValueTraitsStringConv mode> template <bindings::NativeValueTraitsStringConv mode>
...@@ -469,6 +663,18 @@ struct NativeValueTraits<IDLStringBaseV2<mode>> ...@@ -469,6 +663,18 @@ struct NativeValueTraits<IDLStringBaseV2<mode>>
} }
return bindings::NativeValueTraitsStringAdapter(v8_string); return bindings::NativeValueTraitsStringAdapter(v8_string);
} }
static bindings::NativeValueTraitsStringAdapter ArgumentValue(
v8::Isolate* isolate,
int argument_index,
v8::Local<v8::Value> value,
ExceptionState& exception_state) {
return NativeValue(isolate, value, exception_state);
}
static bindings::NativeValueTraitsStringAdapter NullValue() {
return bindings::NativeValueTraitsStringAdapter();
}
}; };
template <bindings::NativeValueTraitsStringConv mode> template <bindings::NativeValueTraitsStringConv mode>
...@@ -485,6 +691,15 @@ struct NativeValueTraits<IDLUSVStringBaseV2<mode>> ...@@ -485,6 +691,15 @@ struct NativeValueTraits<IDLUSVStringBaseV2<mode>>
return ReplaceUnmatchedSurrogates(string); return ReplaceUnmatchedSurrogates(string);
} }
static String ArgumentValue(v8::Isolate* isolate,
int argument_index,
v8::Local<v8::Value> value,
ExceptionState& exception_state) {
return NativeValue(isolate, value, exception_state);
}
static String NullValue() { return String(); }
}; };
// Floats and doubles // Floats and doubles
...@@ -496,6 +711,13 @@ struct CORE_EXPORT NativeValueTraits<IDLDouble> ...@@ -496,6 +711,13 @@ struct CORE_EXPORT NativeValueTraits<IDLDouble>
ExceptionState& exception_state) { ExceptionState& exception_state) {
return ToRestrictedDouble(isolate, value, exception_state); return ToRestrictedDouble(isolate, value, exception_state);
} }
static double ArgumentValue(v8::Isolate* isolate,
int argument_index,
v8::Local<v8::Value> value,
ExceptionState& exception_state) {
return NativeValue(isolate, value, exception_state);
}
}; };
template <> template <>
...@@ -506,6 +728,13 @@ struct CORE_EXPORT NativeValueTraits<IDLUnrestrictedDouble> ...@@ -506,6 +728,13 @@ struct CORE_EXPORT NativeValueTraits<IDLUnrestrictedDouble>
ExceptionState& exception_state) { ExceptionState& exception_state) {
return ToDouble(isolate, value, exception_state); return ToDouble(isolate, value, exception_state);
} }
static double ArgumentValue(v8::Isolate* isolate,
int argument_index,
v8::Local<v8::Value> value,
ExceptionState& exception_state) {
return NativeValue(isolate, value, exception_state);
}
}; };
template <> template <>
...@@ -516,6 +745,13 @@ struct CORE_EXPORT NativeValueTraits<IDLFloat> ...@@ -516,6 +745,13 @@ struct CORE_EXPORT NativeValueTraits<IDLFloat>
ExceptionState& exception_state) { ExceptionState& exception_state) {
return ToRestrictedFloat(isolate, value, exception_state); return ToRestrictedFloat(isolate, value, exception_state);
} }
static float ArgumentValue(v8::Isolate* isolate,
int argument_index,
v8::Local<v8::Value> value,
ExceptionState& exception_state) {
return NativeValue(isolate, value, exception_state);
}
}; };
template <> template <>
...@@ -526,6 +762,13 @@ struct CORE_EXPORT NativeValueTraits<IDLUnrestrictedFloat> ...@@ -526,6 +762,13 @@ struct CORE_EXPORT NativeValueTraits<IDLUnrestrictedFloat>
ExceptionState& exception_state) { ExceptionState& exception_state) {
return ToFloat(isolate, value, exception_state); return ToFloat(isolate, value, exception_state);
} }
static float ArgumentValue(v8::Isolate* isolate,
int argument_index,
v8::Local<v8::Value> value,
ExceptionState& exception_state) {
return NativeValue(isolate, value, exception_state);
}
}; };
// Buffer source types // Buffer source types
...@@ -643,6 +886,13 @@ struct NativeValueTraits<IDLSequence<T>> ...@@ -643,6 +886,13 @@ struct NativeValueTraits<IDLSequence<T>>
return result; return result;
} }
static ImplType ArgumentValue(v8::Isolate* isolate,
int argument_index,
v8::Local<v8::Value> value,
ExceptionState& exception_state) {
return NativeValue(isolate, value, exception_state);
}
private: private:
// Fast case: we're interating over an Array that adheres to // Fast case: we're interating over an Array that adheres to
// %ArrayIteratorPrototype%'s protocol. // %ArrayIteratorPrototype%'s protocol.
...@@ -830,13 +1080,20 @@ struct NativeValueTraits<IDLRecord<K, V>> ...@@ -830,13 +1080,20 @@ struct NativeValueTraits<IDLRecord<K, V>>
// "5. Return result." // "5. Return result."
return result; return result;
} }
static ImplType ArgumentValue(v8::Isolate* isolate,
int argument_index,
v8::Local<v8::Value> value,
ExceptionState& exception_state) {
return NativeValue(isolate, value, exception_state);
}
}; };
// Callback functions // Callback functions
template <typename T> template <typename T>
struct NativeValueTraits< struct NativeValueTraits<
T, T,
std::enable_if_t<std::is_base_of<CallbackFunctionBase, T>::value>> typename std::enable_if_t<std::is_base_of<CallbackFunctionBase, T>::value>>
: public NativeValueTraitsBase<T> { : public NativeValueTraitsBase<T> {
static T* NativeValue(v8::Isolate* isolate, static T* NativeValue(v8::Isolate* isolate,
v8::Local<v8::Value> value, v8::Local<v8::Value> value,
...@@ -850,6 +1107,13 @@ struct NativeValueTraits< ...@@ -850,6 +1107,13 @@ struct NativeValueTraits<
<< "is not yet implemented."; << "is not yet implemented.";
return nullptr; return nullptr;
} }
static T* ArgumentValue(v8::Isolate* isolate,
int argument_index,
v8::Local<v8::Value> value,
ExceptionState& exception_state) {
return NativeValue(isolate, value, exception_state);
}
}; };
// Dictionary // Dictionary
...@@ -864,6 +1128,13 @@ struct NativeValueTraits< ...@@ -864,6 +1128,13 @@ struct NativeValueTraits<
ExceptionState& exception_state) { ExceptionState& exception_state) {
return T::Create(isolate, value, exception_state); return T::Create(isolate, value, exception_state);
} }
static T* ArgumentValue(v8::Isolate* isolate,
int argument_index,
v8::Local<v8::Value> value,
ExceptionState& exception_state) {
return NativeValue(isolate, value, exception_state);
}
}; };
// Interface // Interface
...@@ -880,6 +1151,16 @@ struct NativeValueTraits< ...@@ -880,6 +1151,16 @@ struct NativeValueTraits<
->template ToImpl<T>(); ->template ToImpl<T>();
} }
static T* ArgumentValue(v8::Isolate* isolate,
int argument_index,
v8::Local<v8::Value> value,
ExceptionState& exception_state) {
return bindings::NativeValueTraitsInterfaceArgumentValue(
isolate, T::GetStaticWrapperTypeInfo(), argument_index, value,
exception_state)
->template ToImpl<T>();
}
static constexpr T* NullValue() { return nullptr; } static constexpr T* NullValue() { return nullptr; }
}; };
...@@ -897,6 +1178,14 @@ struct NativeValueTraits<IDLNullable<InnerType>> ...@@ -897,6 +1178,14 @@ struct NativeValueTraits<IDLNullable<InnerType>>
return NativeValueTraits<InnerType>::NativeValue(isolate, v8_value, return NativeValueTraits<InnerType>::NativeValue(isolate, v8_value,
exception_state); exception_state);
} }
static typename IDLNullable<InnerType>::ResultType ArgumentValue(
v8::Isolate* isolate,
int argument_index,
v8::Local<v8::Value> value,
ExceptionState& exception_state) {
return NativeValue(isolate, value, exception_state);
}
}; };
} // namespace blink } // namespace blink
......
...@@ -174,12 +174,13 @@ def native_value_tag(idl_type): ...@@ -174,12 +174,13 @@ def native_value_tag(idl_type):
assert isinstance(idl_type, web_idl.IdlType) assert isinstance(idl_type, web_idl.IdlType)
real_type = idl_type.unwrap(typedef=True) 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 real_type.is_any if (real_type.is_boolean or real_type.is_numeric
or real_type.is_object): or non_null_real_type.is_any or non_null_real_type.is_object):
return "IDL{}".format(real_type.type_name) return "IDL{}".format(real_type.type_name)
if real_type.unwrap(nullable=True).is_string: if non_null_real_type.is_string:
return "IDL{}V2".format(real_type.type_name) return "IDL{}V2".format(real_type.type_name)
if real_type.is_symbol: if real_type.is_symbol:
...@@ -188,10 +189,10 @@ def native_value_tag(idl_type): ...@@ -188,10 +189,10 @@ def native_value_tag(idl_type):
if real_type.is_void: if real_type.is_void:
assert False, "Blink does not support/accept IDL void type." assert False, "Blink does not support/accept IDL void type."
if real_type.type_definition_object is not None: if non_null_real_type.type_definition_object:
return blink_type_info(real_type).value_t return blink_class_name(non_null_real_type.type_definition_object)
if real_type.is_sequence: if real_type.is_sequence or real_type.is_frozen_array:
return "IDLSequence<{}>".format( return "IDLSequence<{}>".format(
native_value_tag(real_type.element_type)) native_value_tag(real_type.element_type))
...@@ -209,7 +210,7 @@ def native_value_tag(idl_type): ...@@ -209,7 +210,7 @@ def native_value_tag(idl_type):
if real_type.is_nullable: if real_type.is_nullable:
return "IDLNullable<{}>".format(native_value_tag(real_type.inner_type)) return "IDLNullable<{}>".format(native_value_tag(real_type.inner_type))
assert False assert False, "Unknown type: {}".format(idl_type.syntactic_form)
def make_default_value_expr(idl_type, default_value): def make_default_value_expr(idl_type, default_value):
...@@ -307,6 +308,7 @@ def make_default_value_expr(idl_type, default_value): ...@@ -307,6 +308,7 @@ def make_default_value_expr(idl_type, default_value):
def make_v8_to_blink_value(blink_var_name, def make_v8_to_blink_value(blink_var_name,
v8_value_expr, v8_value_expr,
idl_type, idl_type,
argument_index=None,
default_value=None): default_value=None):
""" """
Returns a SymbolNode whose definition converts a v8::Value to a Blink value. Returns a SymbolNode whose definition converts a v8::Value to a Blink value.
...@@ -314,6 +316,7 @@ def make_v8_to_blink_value(blink_var_name, ...@@ -314,6 +316,7 @@ def make_v8_to_blink_value(blink_var_name,
assert isinstance(blink_var_name, str) assert isinstance(blink_var_name, str)
assert isinstance(v8_value_expr, str) assert isinstance(v8_value_expr, str)
assert isinstance(idl_type, web_idl.IdlType) assert isinstance(idl_type, web_idl.IdlType)
assert (argument_index is None or isinstance(argument_index, (int, long)))
assert (default_value is None assert (default_value is None
or isinstance(default_value, web_idl.LiteralConstant)) or isinstance(default_value, web_idl.LiteralConstant))
...@@ -321,10 +324,22 @@ def make_v8_to_blink_value(blink_var_name, ...@@ -321,10 +324,22 @@ def make_v8_to_blink_value(blink_var_name,
F = lambda *args, **kwargs: T(_format(*args, **kwargs)) F = lambda *args, **kwargs: T(_format(*args, **kwargs))
def create_definition(symbol_node): def create_definition(symbol_node):
blink_value_expr = _format( if argument_index is None:
"NativeValueTraits<{_1}>::NativeValue({_2})", blink_value_expr = _format(
_1=native_value_tag(idl_type), "NativeValueTraits<{_1}>::NativeValue({_2})",
_2=", ".join(["${isolate}", v8_value_expr, "${exception_state}"])) _1=native_value_tag(idl_type),
_2=", ".join(
["${isolate}", v8_value_expr, "${exception_state}"]))
else:
blink_value_expr = _format(
"NativeValueTraits<{_1}>::ArgumentValue({_2})",
_1=native_value_tag(idl_type),
_2=", ".join([
"${isolate}",
str(argument_index),
v8_value_expr,
"${exception_state}",
]))
if default_value is None: if default_value is None:
return SymbolDefinitionNode(symbol_node, [ return SymbolDefinitionNode(symbol_node, [
......
...@@ -147,8 +147,12 @@ def bind_blink_api_arguments(code_node, cg_context): ...@@ -147,8 +147,12 @@ def bind_blink_api_arguments(code_node, cg_context):
else: else:
v8_value = "${{info}}[{}]".format(argument.index) v8_value = "${{info}}[{}]".format(argument.index)
code_node.register_code_symbol( code_node.register_code_symbol(
make_v8_to_blink_value(name, v8_value, argument.idl_type, make_v8_to_blink_value(
argument.default_value)) name,
v8_value,
argument.idl_type,
argument_index=index,
default_value=argument.default_value))
def bind_callback_local_vars(code_node, cg_context): def bind_callback_local_vars(code_node, cg_context):
...@@ -2957,5 +2961,5 @@ def generate_interface(interface): ...@@ -2957,5 +2961,5 @@ def generate_interface(interface):
def generate_interfaces(web_idl_database): def generate_interfaces(web_idl_database):
interface = web_idl_database.find("Navigator") interface = web_idl_database.find("Node")
generate_interface(interface) generate_interface(interface)
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