blob: 7d7dd42f0d0ad535cc082204cb0b8fa238f07fab [file] [log] [blame]
// Copyright 2018 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// clang-format off
// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY!
// Auto-generated from template: bindings/v8c/templates/interface.cc.template
#include "cobalt/bindings/testing/v8c_derived_getter_setter_interface.h"
#include "base/debug/trace_event.h"
#include "cobalt/base/polymorphic_downcast.h"
#include "cobalt/script/global_environment.h"
#include "cobalt/script/script_value.h"
#include "cobalt/script/value_handle.h"
#include "cobalt/bindings/testing/named_indexed_getter_interface.h"
#include "cobalt/bindings/testing/v8c_named_indexed_getter_interface.h"
#include "v8c_gen_type_conversion.h"
#include "cobalt/script/callback_interface_traits.h"
#include "cobalt/script/v8c/callback_function_conversion.h"
#include "cobalt/script/v8c/conversion_helpers.h"
#include "cobalt/script/v8c/entry_scope.h"
#include "cobalt/script/v8c/helpers.h"
#include "cobalt/script/v8c/native_promise.h"
#include "cobalt/script/v8c/type_traits.h"
#include "cobalt/script/v8c/v8c_callback_function.h"
#include "cobalt/script/v8c/v8c_callback_interface_holder.h"
#include "cobalt/script/v8c/v8c_engine.h"
#include "cobalt/script/v8c/v8c_exception_state.h"
#include "cobalt/script/v8c/v8c_global_environment.h"
#include "cobalt/script/v8c/v8c_property_enumerator.h"
#include "cobalt/script/v8c/v8c_value_handle.h"
#include "cobalt/script/v8c/wrapper_private.h"
#include "v8/include/v8.h"
namespace {
using cobalt::bindings::testing::DerivedGetterSetterInterface;
using cobalt::bindings::testing::V8cDerivedGetterSetterInterface;
using cobalt::bindings::testing::NamedIndexedGetterInterface;
using cobalt::bindings::testing::V8cNamedIndexedGetterInterface;
using cobalt::script::CallbackInterfaceTraits;
using cobalt::script::GlobalEnvironment;
using cobalt::script::ScriptValue;
using cobalt::script::ValueHandle;
using cobalt::script::ValueHandle;
using cobalt::script::ValueHandleHolder;
using cobalt::script::Wrappable;
using cobalt::script::v8c::EntryScope;
using cobalt::script::v8c::EscapableEntryScope;
using cobalt::script::v8c::FromJSValue;
using cobalt::script::v8c::kConversionFlagClamped;
using cobalt::script::v8c::kConversionFlagNullable;
using cobalt::script::v8c::kConversionFlagObjectOnly;
using cobalt::script::v8c::kConversionFlagRestricted;
using cobalt::script::v8c::kConversionFlagTreatNullAsEmptyString;
using cobalt::script::v8c::kConversionFlagTreatUndefinedAsEmptyString;
using cobalt::script::v8c::kNoConversionFlags;
using cobalt::script::v8c::NewInternalString;
using cobalt::script::v8c::ToJSValue;
using cobalt::script::v8c::TypeTraits;
using cobalt::script::v8c::V8cExceptionState;
using cobalt::script::v8c::V8cGlobalEnvironment;
using cobalt::script::v8c::V8cPropertyEnumerator;
using cobalt::script::v8c::WrapperFactory;
using cobalt::script::v8c::WrapperPrivate;
} // namespace
namespace cobalt {
namespace bindings {
namespace testing {
namespace {
const int kInterfaceUniqueId = 15;
void NamedPropertyGetterCallback(
v8::Local<v8::Name> property,
const v8::PropertyCallbackInfo<v8::Value>& info) {
v8::Isolate* isolate = info.GetIsolate();
v8::Local<v8::Object> object = info.Holder();
V8cExceptionState exception_state{isolate};
v8::Local<v8::Value> result_value;
WrapperPrivate* wrapper_private =
WrapperPrivate::GetFromWrapperObject(object);
if (!wrapper_private) {
NOTIMPLEMENTED();
return;
}
DerivedGetterSetterInterface* impl =
wrapper_private->wrappable<DerivedGetterSetterInterface>().get();
std::string property_name = *v8::String::Utf8Value(isolate, property);
if (!impl->CanQueryNamedProperty(property_name)) {
return;
}
if (!exception_state.is_exception_set()) {
ToJSValue(isolate,
impl->AnonymousNamedGetter(property_name),
&result_value);
}
if (exception_state.is_exception_set()) {
return;
}
info.GetReturnValue().Set(result_value);
DCHECK(!exception_state.is_exception_set());
}
void NamedPropertyQueryCallback(
v8::Local<v8::Name> property,
const v8::PropertyCallbackInfo<v8::Integer>& info) {
v8::Isolate* isolate = info.GetIsolate();
v8::Local<v8::Object> object = info.Holder();
WrapperPrivate* wrapper_private =
WrapperPrivate::GetFromWrapperObject(object);
if (!wrapper_private) {
NOTIMPLEMENTED();
return;
}
DerivedGetterSetterInterface* impl =
wrapper_private->wrappable<DerivedGetterSetterInterface>().get();
std::string property_name = *v8::String::Utf8Value(isolate, property);
bool result = impl->CanQueryNamedProperty(property_name);
if (!result) {
return;
}
// https://heycam.github.io/webidl/#LegacyPlatformObjectGetOwnProperty
int properties = v8::None;
// 2.7. If |O| implements an interface with a named property setter, then set
// desc.[[Writable]] to true, otherwise set it to false.
// 2.8. If |O| implements an interface with the
// [LegacyUnenumerableNamedProperties] extended attribute, then set
// desc.[[Enumerable]] to false, otherwise set it to true.
info.GetReturnValue().Set(properties);
}
void NamedPropertyEnumeratorCallback(
const v8::PropertyCallbackInfo<v8::Array>& info) {
v8::Isolate* isolate = info.GetIsolate();
v8::Local<v8::Object> object = info.Holder();
WrapperPrivate* wrapper_private =
WrapperPrivate::GetFromWrapperObject(object);
if (!wrapper_private) {
NOTIMPLEMENTED();
return;
}
DerivedGetterSetterInterface* impl =
wrapper_private->wrappable<DerivedGetterSetterInterface>().get();
v8::Local<v8::Array> array = v8::Array::New(isolate);
V8cPropertyEnumerator property_enumerator(isolate, &array);
impl->EnumerateNamedProperties(&property_enumerator);
info.GetReturnValue().Set(array);
}
void NamedPropertySetterCallback(
v8::Local<v8::Name> property,
v8::Local<v8::Value> value,
const v8::PropertyCallbackInfo<v8::Value>& info) {
v8::Isolate* isolate = info.GetIsolate();
v8::Local<v8::Object> object = info.Holder();
V8cExceptionState exception_state{isolate};
v8::Local<v8::Value> result_value;
WrapperPrivate* wrapper_private =
WrapperPrivate::GetFromWrapperObject(object);
if (!wrapper_private) {
NOTIMPLEMENTED();
return;
}
DerivedGetterSetterInterface* impl =
wrapper_private->wrappable<DerivedGetterSetterInterface>().get();
std::string property_name = *v8::String::Utf8Value(isolate, property);
TypeTraits<std::string>::ConversionType native_value;
FromJSValue(isolate, value, kNoConversionFlags,
&exception_state, &native_value);
if (exception_state.is_exception_set()) {
return;
}
impl->AnonymousNamedSetter(property_name, native_value);
result_value = v8::Undefined(isolate);
info.GetReturnValue().Set(value);
DCHECK(!exception_state.is_exception_set());
}
void IndexedPropertyGetterCallback(
uint32_t index,
const v8::PropertyCallbackInfo<v8::Value>& info) {
v8::Isolate* isolate = info.GetIsolate();
v8::Local<v8::Object> object = info.Holder();
V8cExceptionState exception_state{isolate};
v8::Local<v8::Value> result_value;
WrapperPrivate* wrapper_private =
WrapperPrivate::GetFromWrapperObject(object);
if (!wrapper_private) {
NOTIMPLEMENTED();
return;
}
DerivedGetterSetterInterface* impl =
wrapper_private->wrappable<DerivedGetterSetterInterface>().get();
if (index >= impl->length()) {
// |index| is out of bounds, so return undefined.
return;
}
if (!exception_state.is_exception_set()) {
ToJSValue(isolate,
impl->DerivedIndexedGetter(index),
&result_value);
}
info.GetReturnValue().Set(result_value);
}
void IndexedPropertyDescriptorCallback(
uint32_t index, const v8::PropertyCallbackInfo<v8::Value>& info) {
// TODO: Figure out under what conditions this gets called. It's not
// getting called in our tests.
NOTIMPLEMENTED();
}
void IndexedPropertyEnumeratorCallback(
const v8::PropertyCallbackInfo<v8::Array>& info) {
v8::Isolate* isolate = info.GetIsolate();
v8::Local<v8::Object> object = info.Holder();
WrapperPrivate* wrapper_private =
WrapperPrivate::GetFromWrapperObject(object);
if (!wrapper_private) {
NOTIMPLEMENTED();
return;
}
DerivedGetterSetterInterface* impl =
wrapper_private->wrappable<DerivedGetterSetterInterface>().get();
const uint32_t length = impl->length();
v8::Local<v8::Array> array = v8::Array::New(isolate, length);
for (uint32_t i = 0; i < length; ++i) {
array->Set(i, v8::Integer::New(isolate, i));
}
info.GetReturnValue().Set(array);
}
void IndexedPropertyDefinerCallback(
uint32_t index, const v8::PropertyDescriptor& desc,
const v8::PropertyCallbackInfo<v8::Value>& info) {
// TODO: Figure out under what conditions this gets called. It's not
// getting called in our tests.
NOTIMPLEMENTED();
}
void IndexedPropertySetterCallback(
uint32_t index,
v8::Local<v8::Value> value,
const v8::PropertyCallbackInfo<v8::Value>& info) {
v8::Isolate* isolate = info.GetIsolate();
v8::Local<v8::Object> object = info.Holder();
V8cExceptionState exception_state{isolate};
v8::Local<v8::Value> result_value;
WrapperPrivate* wrapper_private =
WrapperPrivate::GetFromWrapperObject(object);
if (!wrapper_private) {
NOTIMPLEMENTED();
return;
}
DerivedGetterSetterInterface* impl =
wrapper_private->wrappable<DerivedGetterSetterInterface>().get();
if (index >= impl->length()) {
return;
}
TypeTraits<uint32_t>::ConversionType native_value;
FromJSValue(isolate, value, kNoConversionFlags,
&exception_state, &native_value);
if (exception_state.is_exception_set()) {
return;
}
impl->DerivedIndexedSetter(index, native_value);
result_value = v8::Undefined(isolate);
if (exception_state.is_exception_set()) {
return;
}
info.GetReturnValue().Set(value);
}
void DummyConstructor(const v8::FunctionCallbackInfo<v8::Value>& info) {
V8cExceptionState exception(info.GetIsolate());
exception.SetSimpleException(
script::kTypeError, "DerivedGetterSetterInterface is not constructible.");
}
void lengthAttributeGetter(
const v8::FunctionCallbackInfo<v8::Value>& info) {
v8::Isolate* isolate = info.GetIsolate();
v8::Local<v8::Object> object = info.Holder();
V8cGlobalEnvironment* global_environment = V8cGlobalEnvironment::GetFromIsolate(isolate);
WrapperFactory* wrapper_factory = global_environment->wrapper_factory();
if (!WrapperPrivate::HasWrapperPrivate(object) ||
!V8cDerivedGetterSetterInterface::GetTemplate(isolate)->HasInstance(object)) {
V8cExceptionState exception(isolate);
exception.SetSimpleException(script::kDoesNotImplementInterface);
return;
}
V8cExceptionState exception_state{isolate};
v8::Local<v8::Value> result_value;
WrapperPrivate* wrapper_private =
WrapperPrivate::GetFromWrapperObject(object);
if (!wrapper_private) {
NOTIMPLEMENTED();
return;
}
DerivedGetterSetterInterface* impl =
wrapper_private->wrappable<DerivedGetterSetterInterface>().get();
if (!exception_state.is_exception_set()) {
ToJSValue(isolate,
impl->length(),
&result_value);
}
if (exception_state.is_exception_set()) {
return;
}
info.GetReturnValue().Set(result_value);
}
void propertyOnDerivedClassAttributeGetter(
const v8::FunctionCallbackInfo<v8::Value>& info) {
v8::Isolate* isolate = info.GetIsolate();
v8::Local<v8::Object> object = info.Holder();
V8cGlobalEnvironment* global_environment = V8cGlobalEnvironment::GetFromIsolate(isolate);
WrapperFactory* wrapper_factory = global_environment->wrapper_factory();
if (!WrapperPrivate::HasWrapperPrivate(object) ||
!V8cDerivedGetterSetterInterface::GetTemplate(isolate)->HasInstance(object)) {
V8cExceptionState exception(isolate);
exception.SetSimpleException(script::kDoesNotImplementInterface);
return;
}
V8cExceptionState exception_state{isolate};
v8::Local<v8::Value> result_value;
WrapperPrivate* wrapper_private =
WrapperPrivate::GetFromWrapperObject(object);
if (!wrapper_private) {
NOTIMPLEMENTED();
return;
}
DerivedGetterSetterInterface* impl =
wrapper_private->wrappable<DerivedGetterSetterInterface>().get();
if (!exception_state.is_exception_set()) {
ToJSValue(isolate,
impl->property_on_derived_class(),
&result_value);
}
if (exception_state.is_exception_set()) {
return;
}
info.GetReturnValue().Set(result_value);
}
void propertyOnDerivedClassAttributeSetter(
const v8::FunctionCallbackInfo<v8::Value>& info) {
v8::Isolate* isolate = info.GetIsolate();
v8::Local<v8::Object> object = info.Holder();
v8::Local<v8::Value> v8_value = info[0];
V8cGlobalEnvironment* global_environment = V8cGlobalEnvironment::GetFromIsolate(isolate);
WrapperFactory* wrapper_factory = global_environment->wrapper_factory();
if (!WrapperPrivate::HasWrapperPrivate(object) ||
!V8cDerivedGetterSetterInterface::GetTemplate(isolate)->HasInstance(object)) {
V8cExceptionState exception(isolate);
exception.SetSimpleException(script::kDoesNotImplementInterface);
return;
}
V8cExceptionState exception_state{isolate};
v8::Local<v8::Value> result_value;
WrapperPrivate* wrapper_private =
WrapperPrivate::GetFromWrapperObject(object);
if (!wrapper_private) {
NOTIMPLEMENTED();
return;
}
DerivedGetterSetterInterface* impl =
wrapper_private->wrappable<DerivedGetterSetterInterface>().get();
TypeTraits<bool >::ConversionType value;
FromJSValue(isolate, v8_value, kNoConversionFlags, &exception_state,
&value);
if (exception_state.is_exception_set()) {
return;
}
impl->set_property_on_derived_class(value);
result_value = v8::Undefined(isolate);
return;
}
void derivedIndexedGetterMethod(const v8::FunctionCallbackInfo<v8::Value>& info) {
v8::Isolate* isolate = info.GetIsolate();
v8::Local<v8::Object> object = info.Holder();
V8cGlobalEnvironment* global_environment = V8cGlobalEnvironment::GetFromIsolate(isolate);
WrapperFactory* wrapper_factory = global_environment->wrapper_factory();
if (!WrapperPrivate::HasWrapperPrivate(object) ||
!V8cDerivedGetterSetterInterface::GetTemplate(isolate)->HasInstance(object)) {
V8cExceptionState exception(isolate);
exception.SetSimpleException(script::kDoesNotImplementInterface);
return;
}
V8cExceptionState exception_state{isolate};
v8::Local<v8::Value> result_value;
WrapperPrivate* wrapper_private =
WrapperPrivate::GetFromWrapperObject(object);
if (!wrapper_private) {
NOTIMPLEMENTED();
return;
}
DerivedGetterSetterInterface* impl =
wrapper_private->wrappable<DerivedGetterSetterInterface>().get();
const size_t kMinArguments = 1;
if (info.Length() < kMinArguments) {
exception_state.SetSimpleException(script::kInvalidNumberOfArguments);
return;
}
// Non-optional arguments
TypeTraits<uint32_t >::ConversionType index;
DCHECK_LT(0, info.Length());
v8::Local<v8::Value> non_optional_value0 = info[0];
FromJSValue(isolate,
non_optional_value0,
kNoConversionFlags,
&exception_state, &index);
if (exception_state.is_exception_set()) {
return;
}
if (!exception_state.is_exception_set()) {
ToJSValue(isolate,
impl->DerivedIndexedGetter(index),
&result_value);
}
if (!exception_state.is_exception_set()) {
info.GetReturnValue().Set(result_value);
}
}
void derivedIndexedSetterMethod(const v8::FunctionCallbackInfo<v8::Value>& info) {
v8::Isolate* isolate = info.GetIsolate();
v8::Local<v8::Object> object = info.Holder();
V8cGlobalEnvironment* global_environment = V8cGlobalEnvironment::GetFromIsolate(isolate);
WrapperFactory* wrapper_factory = global_environment->wrapper_factory();
if (!WrapperPrivate::HasWrapperPrivate(object) ||
!V8cDerivedGetterSetterInterface::GetTemplate(isolate)->HasInstance(object)) {
V8cExceptionState exception(isolate);
exception.SetSimpleException(script::kDoesNotImplementInterface);
return;
}
V8cExceptionState exception_state{isolate};
v8::Local<v8::Value> result_value;
WrapperPrivate* wrapper_private =
WrapperPrivate::GetFromWrapperObject(object);
if (!wrapper_private) {
NOTIMPLEMENTED();
return;
}
DerivedGetterSetterInterface* impl =
wrapper_private->wrappable<DerivedGetterSetterInterface>().get();
const size_t kMinArguments = 2;
if (info.Length() < kMinArguments) {
exception_state.SetSimpleException(script::kInvalidNumberOfArguments);
return;
}
// Non-optional arguments
TypeTraits<uint32_t >::ConversionType index;
TypeTraits<uint32_t >::ConversionType value;
DCHECK_LT(0, info.Length());
v8::Local<v8::Value> non_optional_value0 = info[0];
FromJSValue(isolate,
non_optional_value0,
kNoConversionFlags,
&exception_state, &index);
if (exception_state.is_exception_set()) {
return;
}
DCHECK_LT(1, info.Length());
v8::Local<v8::Value> non_optional_value1 = info[1];
FromJSValue(isolate,
non_optional_value1,
kNoConversionFlags,
&exception_state, &value);
if (exception_state.is_exception_set()) {
return;
}
impl->DerivedIndexedSetter(index, value);
result_value = v8::Undefined(isolate);
}
void operationOnDerivedClassMethod(const v8::FunctionCallbackInfo<v8::Value>& info) {
v8::Isolate* isolate = info.GetIsolate();
v8::Local<v8::Object> object = info.Holder();
V8cGlobalEnvironment* global_environment = V8cGlobalEnvironment::GetFromIsolate(isolate);
WrapperFactory* wrapper_factory = global_environment->wrapper_factory();
if (!WrapperPrivate::HasWrapperPrivate(object) ||
!V8cDerivedGetterSetterInterface::GetTemplate(isolate)->HasInstance(object)) {
V8cExceptionState exception(isolate);
exception.SetSimpleException(script::kDoesNotImplementInterface);
return;
}
V8cExceptionState exception_state{isolate};
v8::Local<v8::Value> result_value;
WrapperPrivate* wrapper_private =
WrapperPrivate::GetFromWrapperObject(object);
if (!wrapper_private) {
NOTIMPLEMENTED();
return;
}
DerivedGetterSetterInterface* impl =
wrapper_private->wrappable<DerivedGetterSetterInterface>().get();
impl->OperationOnDerivedClass();
result_value = v8::Undefined(isolate);
}
void InitializeTemplate(v8::Isolate* isolate) {
// https://heycam.github.io/webidl/#interface-object
// 3.6.1. Interface object
//
// The interface object for a given interface is a built-in function object.
// It has properties that correspond to the constants and static operations
// defined on that interface, as described in sections 3.6.6 Constants and
// 3.6.8 Operations.
//
// If the interface is declared with a [Constructor] extended attribute,
// then the interface object can be called as a constructor to create an
// object that implements that interface. Calling that interface as a
// function will throw an exception.
//
// Interface objects whose interfaces are not declared with a [Constructor]
// extended attribute will throw when called, both as a function and as a
// constructor.
//
// An interface object for a non-callback interface has an associated object
// called the interface prototype object. This object has properties that
// correspond to the regular attributes and regular operations defined on
// the interface, and is described in more detail in 3.6.3 Interface
// prototype object.
v8::Local<v8::FunctionTemplate> function_template =
v8::FunctionTemplate::New(
isolate,
DummyConstructor,
v8::Local<v8::Value>(),
v8::Local<v8::Signature>(),
0);
function_template->SetClassName(NewInternalString(isolate, "DerivedGetterSetterInterface"));
function_template->ReadOnlyPrototype();
v8::Local<v8::ObjectTemplate> prototype_template = function_template->PrototypeTemplate();
v8::Local<v8::ObjectTemplate> instance_template = function_template->InstanceTemplate();
instance_template->SetInternalFieldCount(WrapperPrivate::kInternalFieldCount);
V8cGlobalEnvironment* global_environment = V8cGlobalEnvironment::GetFromIsolate(isolate);
global_environment->AddInterfaceData(kInterfaceUniqueId, function_template);
{
// An interface can be defined to inherit from another interface. If the
// identifier of the interface is followed by a U+003A COLON (":") character
// and an identifier, then that identifier identifies the inherited
// interface. An object that implements an interface that inherits from
// another also implements that inherited interface. The object therefore
// will also have members that correspond to the interface members from the
// inherited interface.
v8::Local<v8::FunctionTemplate> parent_template = V8cNamedIndexedGetterInterface::GetTemplate(isolate);
function_template->Inherit(parent_template);
}
// https://heycam.github.io/webidl/#es-constants
// 3.6.6. Constants
//
// For each exposed constant defined on an interface A, there must be a
// corresponding property. The property has the following characteristics:
// https://heycam.github.io/webidl/#es-attributes
// 3.6.7. Attributes
//
// For each exposed attribute of the interface there must exist a
// corresponding property. The characteristics of this property are as
// follows:
{
// The name of the property is the identifier of the attribute.
v8::Local<v8::String> name = NewInternalString(
isolate,
"length");
// The property has attributes { [[Get]]: G, [[Set]]: S, [[Enumerable]]:
// true, [[Configurable]]: configurable }, where: configurable is false if
// the attribute was declared with the [Unforgeable] extended attribute and
// true otherwise;
bool configurable = true;
v8::PropertyAttribute attributes = static_cast<v8::PropertyAttribute>(
configurable ? v8::None : v8::DontDelete);
// G is the attribute getter created given the attribute, the interface, and
// the relevant Realm of the object that is the location of the property;
// and
//
// S is the attribute setter created given the attribute, the interface, and
// the relevant Realm of the object that is the location of the property.
v8::Local<v8::FunctionTemplate> getter =
v8::FunctionTemplate::New(isolate, lengthAttributeGetter);
v8::Local<v8::FunctionTemplate> setter;
// The location of the property is determined as follows:
// Otherwise, the property exists solely on the interface's interface
// prototype object.
prototype_template->
SetAccessorProperty(
name,
getter,
setter,
attributes);
}
{
// The name of the property is the identifier of the attribute.
v8::Local<v8::String> name = NewInternalString(
isolate,
"propertyOnDerivedClass");
// The property has attributes { [[Get]]: G, [[Set]]: S, [[Enumerable]]:
// true, [[Configurable]]: configurable }, where: configurable is false if
// the attribute was declared with the [Unforgeable] extended attribute and
// true otherwise;
bool configurable = true;
v8::PropertyAttribute attributes = static_cast<v8::PropertyAttribute>(
configurable ? v8::None : v8::DontDelete);
// G is the attribute getter created given the attribute, the interface, and
// the relevant Realm of the object that is the location of the property;
// and
//
// S is the attribute setter created given the attribute, the interface, and
// the relevant Realm of the object that is the location of the property.
v8::Local<v8::FunctionTemplate> getter =
v8::FunctionTemplate::New(isolate, propertyOnDerivedClassAttributeGetter);
v8::Local<v8::FunctionTemplate> setter =
v8::FunctionTemplate::New(isolate, propertyOnDerivedClassAttributeSetter);
// The location of the property is determined as follows:
// Otherwise, the property exists solely on the interface's interface
// prototype object.
prototype_template->
SetAccessorProperty(
name,
getter,
setter,
attributes);
}
// https://heycam.github.io/webidl/#es-operations
// 3.6.8. Operations
//
// For each unique identifier of an exposed operation defined on the
// interface, there must exist a corresponding property, unless the effective
// overload set for that identifier and operation and with an argument count
// of 0 has no entries.
//
// The characteristics of this property are as follows:
{
// The name of the property is the identifier.
v8::Local<v8::String> name = NewInternalString(
isolate,
"derivedIndexedGetter");
// The property has attributes { [[Writable]]: B, [[Enumerable]]: true,
// [[Configurable]]: B }, where B is false if the operation is unforgeable
// on the interface, and true otherwise.
bool B = true;
v8::PropertyAttribute attributes = static_cast<v8::PropertyAttribute>(
B ? v8::None : (v8::ReadOnly | v8::DontDelete));
v8::Local<v8::FunctionTemplate> method_template =
v8::FunctionTemplate::New(isolate, derivedIndexedGetterMethod);
method_template->RemovePrototype();
method_template->SetLength(1);
// The location of the property is determined as follows:
// Otherwise, the property exists solely on the interface's interface
// prototype object.
prototype_template->
Set(name, method_template);
// The value of the property is the result of creating an operation function
// given the operation, the interface, and the relevant Realm of the object
// that is the location of the property.
// Note: that is, even if an includes statement was used to make an
// operation available on the interface, we pass in the interface which
// includes the interface mixin, and not the interface mixin on which the
// operation was originally declared.
}
{
// The name of the property is the identifier.
v8::Local<v8::String> name = NewInternalString(
isolate,
"derivedIndexedSetter");
// The property has attributes { [[Writable]]: B, [[Enumerable]]: true,
// [[Configurable]]: B }, where B is false if the operation is unforgeable
// on the interface, and true otherwise.
bool B = true;
v8::PropertyAttribute attributes = static_cast<v8::PropertyAttribute>(
B ? v8::None : (v8::ReadOnly | v8::DontDelete));
v8::Local<v8::FunctionTemplate> method_template =
v8::FunctionTemplate::New(isolate, derivedIndexedSetterMethod);
method_template->RemovePrototype();
method_template->SetLength(2);
// The location of the property is determined as follows:
// Otherwise, the property exists solely on the interface's interface
// prototype object.
prototype_template->
Set(name, method_template);
// The value of the property is the result of creating an operation function
// given the operation, the interface, and the relevant Realm of the object
// that is the location of the property.
// Note: that is, even if an includes statement was used to make an
// operation available on the interface, we pass in the interface which
// includes the interface mixin, and not the interface mixin on which the
// operation was originally declared.
}
{
// The name of the property is the identifier.
v8::Local<v8::String> name = NewInternalString(
isolate,
"operationOnDerivedClass");
// The property has attributes { [[Writable]]: B, [[Enumerable]]: true,
// [[Configurable]]: B }, where B is false if the operation is unforgeable
// on the interface, and true otherwise.
bool B = true;
v8::PropertyAttribute attributes = static_cast<v8::PropertyAttribute>(
B ? v8::None : (v8::ReadOnly | v8::DontDelete));
v8::Local<v8::FunctionTemplate> method_template =
v8::FunctionTemplate::New(isolate, operationOnDerivedClassMethod);
method_template->RemovePrototype();
method_template->SetLength(0);
// The location of the property is determined as follows:
// Otherwise, the property exists solely on the interface's interface
// prototype object.
prototype_template->
Set(name, method_template);
// The value of the property is the result of creating an operation function
// given the operation, the interface, and the relevant Realm of the object
// that is the location of the property.
// Note: that is, even if an includes statement was used to make an
// operation available on the interface, we pass in the interface which
// includes the interface mixin, and not the interface mixin on which the
// operation was originally declared.
}
// https://heycam.github.io/webidl/#es-stringifier
// 3.6.8.2. Stringifiers
prototype_template->Set(
v8::Symbol::GetToStringTag(isolate),
NewInternalString(isolate, "DerivedGetterSetterInterface"),
static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontEnum));
{
v8::NamedPropertyHandlerConfiguration named_property_handler_configuration = {
NamedPropertyGetterCallback,
NamedPropertySetterCallback,
NamedPropertyQueryCallback,
nullptr,
NamedPropertyEnumeratorCallback,
v8::Local<v8::Value>(),
static_cast<v8::PropertyHandlerFlags>(int(v8::PropertyHandlerFlags::kNonMasking) | int(v8::PropertyHandlerFlags::kOnlyInterceptStrings))
};
instance_template->SetHandler(named_property_handler_configuration);
}
{
v8::IndexedPropertyHandlerConfiguration indexed_property_handler_configuration = {
IndexedPropertyGetterCallback,
IndexedPropertySetterCallback,
IndexedPropertyDescriptorCallback,
nullptr,
IndexedPropertyEnumeratorCallback,
IndexedPropertyDefinerCallback
};
instance_template->SetHandler(indexed_property_handler_configuration);
}
}
} // namespace
v8::Local<v8::Object> V8cDerivedGetterSetterInterface::CreateWrapper(
v8::Isolate* isolate, const scoped_refptr<Wrappable>& wrappable) {
EscapableEntryScope entry_scope(isolate);
v8::Local<v8::Context> context = isolate->GetCurrentContext();
V8cGlobalEnvironment* global_environment = V8cGlobalEnvironment::GetFromIsolate(isolate);
if (!global_environment->HasInterfaceData(kInterfaceUniqueId)) {
InitializeTemplate(isolate);
}
v8::Local<v8::FunctionTemplate> function_template = global_environment->GetInterfaceData(kInterfaceUniqueId);
DCHECK(function_template->InstanceTemplate()->InternalFieldCount() == WrapperPrivate::kInternalFieldCount);
v8::Local<v8::Object> object = function_template->InstanceTemplate()->NewInstance(context).ToLocalChecked();
DCHECK(object->InternalFieldCount() == WrapperPrivate::kInternalFieldCount);
// This |WrapperPrivate|'s lifetime will be managed by V8.
new WrapperPrivate(isolate, wrappable, object);
return entry_scope.Escape(object);
}
v8::Local<v8::FunctionTemplate> V8cDerivedGetterSetterInterface::GetTemplate(v8::Isolate* isolate) {
V8cGlobalEnvironment* global_environment = V8cGlobalEnvironment::GetFromIsolate(isolate);
if (!global_environment->HasInterfaceData(kInterfaceUniqueId)) {
InitializeTemplate(isolate);
}
return global_environment->GetInterfaceData(kInterfaceUniqueId);
}
} // namespace testing
} // namespace bindings
} // namespace cobalt