Import Cobalt 13.97306
Change-Id: I020449eacf32503499df667c9ca6df3d3ea2b715
diff --git a/src/base/debug/debugger_starboard.cc b/src/base/debug/debugger_starboard.cc
index ee9e762..6945358 100644
--- a/src/base/debug/debugger_starboard.cc
+++ b/src/base/debug/debugger_starboard.cc
@@ -26,7 +26,7 @@
}
bool BeingDebugged() {
-#if defined(__LB_SHELL__FOR_RELEASE__)
+#if defined(COBALT_BUILD_TYPE_GOLD)
return false;
#else
return SbSystemIsDebuggerAttached();
diff --git a/src/base/logging.h b/src/base/logging.h
index 238db8c..0f665ca 100644
--- a/src/base/logging.h
+++ b/src/base/logging.h
@@ -471,7 +471,7 @@
// defined.
#if ( defined(OS_WIN) && defined(OFFICIAL_BUILD)) || \
(!defined(OS_WIN) && defined(NDEBUG) && defined(GOOGLE_CHROME_BUILD)) || \
- defined(__LB_SHELL__FOR_RELEASE__)
+ defined(COBALT_BUILD_TYPE_GOLD)
#define LOGGING_IS_OFFICIAL_BUILD 1
#else
#define LOGGING_IS_OFFICIAL_BUILD 0
@@ -618,7 +618,7 @@
#define CHECK_GT(val1, val2) CHECK_OP(GT, > , val1, val2)
#if LOGGING_IS_OFFICIAL_BUILD || \
- (defined(__LB_SHELL__FOR_QA__) && !defined(__LB_SHELL__FORCE_LOGGING__))
+ (defined(COBALT_BUILD_TYPE_QA) && !defined(__LB_SHELL__FORCE_LOGGING__))
// In order to have optimized code for official builds, remove DLOGs and
// DCHECKs.
#define ENABLE_DLOG 0
@@ -1052,7 +1052,7 @@
#ifndef NOTIMPLEMENTED_POLICY
#if (defined(OS_ANDROID) && defined(OFFICIAL_BUILD)) || \
- defined(__LB_SHELL__FOR_RELEASE__)
+ defined(COBALT_BUILD_TYPE_GOLD)
#define NOTIMPLEMENTED_POLICY 0
#elif defined (__LB_SHELL__) || defined(COBALT)
// Only print each message once.
diff --git a/src/base/logging_unittest.cc b/src/base/logging_unittest.cc
index f0e9f56..8fbe9c7 100644
--- a/src/base/logging_unittest.cc
+++ b/src/base/logging_unittest.cc
@@ -215,7 +215,7 @@
}
TEST_F(LoggingTest, Dcheck) {
-#if LOGGING_IS_OFFICIAL_BUILD
+#if LOGGING_IS_OFFICIAL_BUILD || defined(COBALT_BUILD_TYPE_QA)
// Official build.
EXPECT_FALSE(DCHECK_IS_ON());
EXPECT_FALSE(DLOG_IS_ON(DCHECK));
diff --git a/src/base/metrics/histogram.h b/src/base/metrics/histogram.h
index 74474f3..9fbe631 100644
--- a/src/base/metrics/histogram.h
+++ b/src/base/metrics/histogram.h
@@ -285,7 +285,7 @@
// to record histogram data, and have the data submitted/uploaded via UMA.
// Not all systems support such UMA, but if they do, the following macros
// should work with the service.
-#if defined(__LB_SHELL__FOR_RELEASE__)
+#if defined(COBALT_BUILD_TYPE_GOLD)
#define UMA_HISTOGRAM_TIMES(name, sample) DISCARD_2_ARGUMENTS(name, sample)
#define UMA_HISTOGRAM_MEDIUM_TIMES(name, sample) \
@@ -372,7 +372,7 @@
STATIC_HISTOGRAM_POINTER_BLOCK(name, Add(sample), \
base::CustomHistogram::FactoryGet(name, custom_ranges, \
base::Histogram::kUmaTargetedHistogramFlag))
-#endif // defined(__LB_SHELL__FOR_RELEASE__)
+#endif // defined(COBALT_BUILD_TYPE_GOLD)
//------------------------------------------------------------------------------
diff --git a/src/base/test/main_hook.cc b/src/base/test/main_hook.cc
index d385198..e8e6db0 100644
--- a/src/base/test/main_hook.cc
+++ b/src/base/test/main_hook.cc
@@ -9,7 +9,7 @@
#include "base/command_line.h"
#endif
-#if defined(__LB_SHELL__FOR_RELEASE__)
+#if defined(COBALT_BUILD_TYPE_GOLD)
#error You cannot build unit tests in gold builds.
#endif
diff --git a/src/base/tracked_objects.cc b/src/base/tracked_objects.cc
index 9165169..b4ceb23 100644
--- a/src/base/tracked_objects.cc
+++ b/src/base/tracked_objects.cc
@@ -22,7 +22,7 @@
namespace {
// Flag to compile out almost all of the task tracking code.
-#if defined(__LB_SHELL__FOR_RELEASE__)
+#if defined(COBALT_BUILD_TYPE_GOLD)
const bool kTrackAllTaskObjects = false;
#else
const bool kTrackAllTaskObjects = true;
diff --git a/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/derived_dictionary.h b/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/derived_dictionary.h
deleted file mode 100644
index cd27ab6..0000000
--- a/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/derived_dictionary.h
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * Copyright 2017 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/templates/dictionary.h.template
-
-#ifndef DerivedDictionary_h
-#define DerivedDictionary_h
-
-#include <string>
-
-#include "base/optional.h"
-#include "cobalt/script/script_value.h"
-#include "cobalt/script/sequence.h"
-#include "cobalt/script/value_handle.h"
-#include "cobalt/bindings/testing/test_dictionary.h"
-
-using cobalt::bindings::testing::TestDictionary;
-
-namespace cobalt {
-namespace bindings {
-namespace testing {
-
-class DerivedDictionary : public cobalt::bindings::testing::TestDictionary {
- public:
- DerivedDictionary() {
- additional_member_ = false;
- }
-
- DerivedDictionary(const DerivedDictionary& other)
- : cobalt::bindings::testing::TestDictionary(other) {
- additional_member_ = other.additional_member_;
- }
-
- DerivedDictionary& operator=(const DerivedDictionary& other) {
- cobalt::bindings::testing::TestDictionary::operator=(other);
- additional_member_ = other.additional_member_;
- return *this;
- }
-
- bool has_additional_member() const {
- return true;
- }
- bool additional_member() const {
- return additional_member_;
- }
- void set_additional_member(bool value) {
- additional_member_ = value;
- }
-
- private:
- bool additional_member_;
-};
-
-// This ostream override is necessary for MOCK_METHODs commonly used
-// in idl test code
-inline std::ostream& operator<<(
- std::ostream& stream, const cobalt::bindings::testing::DerivedDictionary& in) {
- UNREFERENCED_PARAMETER(in);
- stream << "[DerivedDictionary]";
- return stream;
-}
-
-} // namespace cobalt
-} // namespace bindings
-} // namespace testing
-
-#endif // DerivedDictionary_h
diff --git a/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/dictionary_with_dictionary_member.h b/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/dictionary_with_dictionary_member.h
deleted file mode 100644
index 02dbce6..0000000
--- a/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/dictionary_with_dictionary_member.h
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
- * Copyright 2017 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/templates/dictionary.h.template
-
-#ifndef DictionaryWithDictionaryMember_h
-#define DictionaryWithDictionaryMember_h
-
-#include <string>
-
-#include "base/optional.h"
-#include "cobalt/script/script_value.h"
-#include "cobalt/script/sequence.h"
-#include "cobalt/script/value_handle.h"
-#include "cobalt/bindings/testing/test_dictionary.h"
-
-using cobalt::bindings::testing::TestDictionary;
-
-namespace cobalt {
-namespace bindings {
-namespace testing {
-
-class DictionaryWithDictionaryMember {
- public:
- DictionaryWithDictionaryMember() {
- has_nested_dictionary_ = false;
- nested_dictionary_ = TestDictionary();
- }
-
- DictionaryWithDictionaryMember(const DictionaryWithDictionaryMember& other) {
- has_nested_dictionary_ = other.has_nested_dictionary_;
- nested_dictionary_ = other.nested_dictionary_;
- }
-
- DictionaryWithDictionaryMember& operator=(const DictionaryWithDictionaryMember& other) {
- has_nested_dictionary_ = other.has_nested_dictionary_;
- nested_dictionary_ = other.nested_dictionary_;
- return *this;
- }
-
- bool has_nested_dictionary() const {
- return has_nested_dictionary_;
- }
- TestDictionary nested_dictionary() const {
- DCHECK(has_nested_dictionary_);
- return nested_dictionary_;
- }
- void set_nested_dictionary(TestDictionary value) {
- has_nested_dictionary_ = true;
- nested_dictionary_ = value;
- }
-
- private:
- bool has_nested_dictionary_;
- TestDictionary nested_dictionary_;
-};
-
-// This ostream override is necessary for MOCK_METHODs commonly used
-// in idl test code
-inline std::ostream& operator<<(
- std::ostream& stream, const cobalt::bindings::testing::DictionaryWithDictionaryMember& in) {
- UNREFERENCED_PARAMETER(in);
- stream << "[DictionaryWithDictionaryMember]";
- return stream;
-}
-
-} // namespace cobalt
-} // namespace bindings
-} // namespace testing
-
-#endif // DictionaryWithDictionaryMember_h
diff --git a/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_anonymous_indexed_getter_interface.cc b/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_anonymous_indexed_getter_interface.cc
deleted file mode 100644
index 806ac70..0000000
--- a/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_anonymous_indexed_getter_interface.cc
+++ /dev/null
@@ -1,507 +0,0 @@
-// Copyright 2017 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/mozjs/templates/interface.cc.template
-
-#include "cobalt/bindings/testing/mozjs_anonymous_indexed_getter_interface.h"
-
-#include "base/debug/trace_event.h"
-#include "cobalt/base/polymorphic_downcast.h"
-#include "cobalt/script/global_environment.h"
-#include "cobalt/script/opaque_handle.h"
-#include "cobalt/script/script_value.h"
-
-#include "mozjs_gen_type_conversion.h"
-
-#include "base/lazy_instance.h"
-#include "cobalt/script/exception_state.h"
-#include "cobalt/script/mozjs/callback_function_conversion.h"
-#include "cobalt/script/mozjs/conversion_helpers.h"
-#include "cobalt/script/mozjs/mozjs_callback_function.h"
-#include "cobalt/script/mozjs/mozjs_exception_state.h"
-#include "cobalt/script/mozjs/mozjs_global_environment.h"
-#include "cobalt/script/mozjs/mozjs_object_handle.h"
-#include "cobalt/script/mozjs/mozjs_property_enumerator.h"
-#include "cobalt/script/mozjs/mozjs_user_object_holder.h"
-#include "cobalt/script/mozjs/mozjs_value_handle.h"
-#include "cobalt/script/mozjs/native_promise.h"
-#include "cobalt/script/mozjs/proxy_handler.h"
-#include "cobalt/script/mozjs/type_traits.h"
-#include "cobalt/script/mozjs/wrapper_factory.h"
-#include "cobalt/script/mozjs/wrapper_private.h"
-#include "cobalt/script/property_enumerator.h"
-#include "cobalt/script/sequence.h"
-#include "third_party/mozjs/js/src/jsapi.h"
-#include "third_party/mozjs/js/src/jsfriendapi.h"
-
-namespace {
-using cobalt::bindings::testing::AnonymousIndexedGetterInterface;
-using cobalt::bindings::testing::MozjsAnonymousIndexedGetterInterface;
-using cobalt::script::CallbackInterfaceTraits;
-using cobalt::script::GlobalEnvironment;
-using cobalt::script::OpaqueHandle;
-using cobalt::script::OpaqueHandleHolder;
-using cobalt::script::ScriptValue;
-using cobalt::script::ValueHandle;
-using cobalt::script::Wrappable;
-
-using cobalt::script::CallbackFunction;
-using cobalt::script::CallbackInterfaceTraits;
-using cobalt::script::ExceptionState;
-using cobalt::script::Wrappable;
-using cobalt::script::mozjs::FromJSValue;
-using cobalt::script::mozjs::InterfaceData;
-using cobalt::script::mozjs::MozjsCallbackFunction;
-using cobalt::script::mozjs::MozjsExceptionState;
-using cobalt::script::mozjs::MozjsGlobalEnvironment;
-using cobalt::script::mozjs::MozjsPropertyEnumerator;
-using cobalt::script::mozjs::MozjsUserObjectHolder;
-using cobalt::script::mozjs::ProxyHandler;
-using cobalt::script::mozjs::ToJSValue;
-using cobalt::script::mozjs::TypeTraits;
-using cobalt::script::mozjs::WrapperFactory;
-using cobalt::script::mozjs::WrapperPrivate;
-using cobalt::script::mozjs::kConversionFlagClamped;
-using cobalt::script::mozjs::kConversionFlagNullable;
-using cobalt::script::mozjs::kConversionFlagRestricted;
-using cobalt::script::mozjs::kConversionFlagTreatNullAsEmptyString;
-using cobalt::script::mozjs::kConversionFlagTreatUndefinedAsEmptyString;
-using cobalt::script::mozjs::kNoConversionFlags;
-} // namespace
-
-namespace cobalt {
-namespace bindings {
-namespace testing {
-
-namespace {
-
-bool IsSupportedIndexProperty(JSContext* context, JS::HandleObject object,
- uint32_t index) {
- WrapperPrivate* wrapper_private =
- WrapperPrivate::GetFromObject(context, object);
- AnonymousIndexedGetterInterface* impl =
- wrapper_private->wrappable<AnonymousIndexedGetterInterface>().get();
- return index < impl->length();
-}
-
-void EnumerateSupportedIndexes(JSContext* context, JS::HandleObject object,
- JS::AutoIdVector* properties) {
- WrapperPrivate* wrapper_private =
- WrapperPrivate::GetFromObject(context, object);
- AnonymousIndexedGetterInterface* impl =
- wrapper_private->wrappable<AnonymousIndexedGetterInterface>().get();
- const uint32_t kNumIndexedProperties = impl->length();
- for (uint32_t i = 0; i < kNumIndexedProperties; ++i) {
- properties->append(INT_TO_JSID(i));
- }
-}
-
-JSBool GetIndexedProperty(
- JSContext* context, JS::HandleObject object, JS::HandleId id,
- JS::MutableHandleValue vp) {
- JS::RootedValue id_value(context);
- if (!JS_IdToValue(context, id, id_value.address())) {
- NOTREACHED();
- return false;
- }
- MozjsExceptionState exception_state(context);
- JS::RootedValue result_value(context);
-
- WrapperPrivate* wrapper_private =
- WrapperPrivate::GetFromObject(context, object);
- AnonymousIndexedGetterInterface* impl =
- wrapper_private->wrappable<AnonymousIndexedGetterInterface>().get();
- uint32_t index;
- FromJSValue(context, id_value, kNoConversionFlags, &exception_state, &index);
- if (exception_state.is_exception_set()) {
- // The ID should be an integer or a string, so we shouldn't have any
- // exceptions converting to string.
- NOTREACHED();
- return false;
- }
-
- if (!exception_state.is_exception_set()) {
- ToJSValue(context,
- impl->AnonymousIndexedGetter(index),
- &result_value);
- }
- if (!exception_state.is_exception_set()) {
- vp.set(result_value);
- }
- return !exception_state.is_exception_set();
-}
-
-JSBool SetIndexedProperty(
- JSContext* context, JS::HandleObject object, JS::HandleId id,
- JSBool strict, JS::MutableHandleValue vp) {
- JS::RootedValue id_value(context);
- if (!JS_IdToValue(context, id, id_value.address())) {
- NOTREACHED();
- return false;
- }
- MozjsExceptionState exception_state(context);
- JS::RootedValue result_value(context);
-
- WrapperPrivate* wrapper_private =
- WrapperPrivate::GetFromObject(context, object);
- AnonymousIndexedGetterInterface* impl =
- wrapper_private->wrappable<AnonymousIndexedGetterInterface>().get();
- uint32_t index;
- FromJSValue(context, id_value, kNoConversionFlags, &exception_state, &index);
- if(exception_state.is_exception_set()) {
- // The ID should be an integer or a string, so we shouldn't have any
- // exceptions converting to string.
- NOTREACHED();
- return false;
- }
- TypeTraits<uint32_t >::ConversionType value;
- FromJSValue(context, vp, kNoConversionFlags,
- &exception_state, &value);
- if (exception_state.is_exception_set()) {
- return false;
- }
-
- impl->AnonymousIndexedSetter(index, value);
- result_value.set(JS::UndefinedHandleValue);
- return !exception_state.is_exception_set();
-}
-
-class MozjsAnonymousIndexedGetterInterfaceHandler : public ProxyHandler {
- public:
- MozjsAnonymousIndexedGetterInterfaceHandler()
- : ProxyHandler(indexed_property_hooks, named_property_hooks) {}
-
- private:
- static NamedPropertyHooks named_property_hooks;
- static IndexedPropertyHooks indexed_property_hooks;
-};
-
-ProxyHandler::NamedPropertyHooks
-MozjsAnonymousIndexedGetterInterfaceHandler::named_property_hooks = {
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
-};
-ProxyHandler::IndexedPropertyHooks
-MozjsAnonymousIndexedGetterInterfaceHandler::indexed_property_hooks = {
- IsSupportedIndexProperty,
- EnumerateSupportedIndexes,
- GetIndexedProperty,
- SetIndexedProperty,
- NULL,
-};
-
-static base::LazyInstance<MozjsAnonymousIndexedGetterInterfaceHandler>
- proxy_handler;
-
-JSBool HasInstance(JSContext *context, JS::HandleObject type,
- JS::MutableHandleValue vp, JSBool *success) {
- JS::RootedObject global_object(
- context, JS_GetGlobalForObject(context, type));
- DCHECK(global_object);
-
- JS::RootedObject prototype(
- context, MozjsAnonymousIndexedGetterInterface::GetPrototype(context, global_object));
-
- // |IsDelegate| walks the prototype chain of an object returning true if
- // .prototype is found.
- bool is_delegate;
- if (!IsDelegate(context, prototype, vp, &is_delegate)) {
- *success = false;
- return false;
- }
-
- *success = is_delegate;
- return true;
-}
-
-InterfaceData* CreateCachedInterfaceData() {
- InterfaceData* interface_data = new InterfaceData();
- memset(&interface_data->instance_class_definition, 0,
- sizeof(interface_data->instance_class_definition));
- memset(&interface_data->prototype_class_definition, 0,
- sizeof(interface_data->prototype_class_definition));
- memset(&interface_data->interface_object_class_definition, 0,
- sizeof(interface_data->interface_object_class_definition));
-
- JSClass* instance_class = &interface_data->instance_class_definition;
- const int kGlobalFlags = 0;
- instance_class->name = "AnonymousIndexedGetterInterface";
- instance_class->flags = kGlobalFlags | JSCLASS_HAS_PRIVATE;
- instance_class->addProperty = JS_PropertyStub;
- instance_class->delProperty = JS_DeletePropertyStub;
- instance_class->getProperty = JS_PropertyStub;
- instance_class->setProperty = JS_StrictPropertyStub;
- instance_class->enumerate = JS_EnumerateStub;
- instance_class->resolve = JS_ResolveStub;
- instance_class->convert = JS_ConvertStub;
- // Function to be called before on object of this class is garbage collected.
- instance_class->finalize = &WrapperPrivate::Finalizer;
- // Called to trace objects that can be referenced from this object.
- instance_class->trace = &WrapperPrivate::Trace;
-
- JSClass* prototype_class = &interface_data->prototype_class_definition;
- prototype_class->name = "AnonymousIndexedGetterInterfacePrototype";
- prototype_class->flags = 0;
- prototype_class->addProperty = JS_PropertyStub;
- prototype_class->delProperty = JS_DeletePropertyStub;
- prototype_class->getProperty = JS_PropertyStub;
- prototype_class->setProperty = JS_StrictPropertyStub;
- prototype_class->enumerate = JS_EnumerateStub;
- prototype_class->resolve = JS_ResolveStub;
- prototype_class->convert = JS_ConvertStub;
-
- JSClass* interface_object_class =
- &interface_data->interface_object_class_definition;
- interface_object_class->name = "AnonymousIndexedGetterInterfaceConstructor";
- interface_object_class->flags = 0;
- interface_object_class->addProperty = JS_PropertyStub;
- interface_object_class->delProperty = JS_DeletePropertyStub;
- interface_object_class->getProperty = JS_PropertyStub;
- interface_object_class->setProperty = JS_StrictPropertyStub;
- interface_object_class->enumerate = JS_EnumerateStub;
- interface_object_class->resolve = JS_ResolveStub;
- interface_object_class->convert = JS_ConvertStub;
- interface_object_class->hasInstance = &HasInstance;
- return interface_data;
-}
-
-JSBool get_length(
- JSContext* context, JS::HandleObject object, JS::HandleId id,
- JS::MutableHandleValue vp) {
- const JSClass* proto_class =
- MozjsAnonymousIndexedGetterInterface::PrototypeClass(context);
- if (proto_class == JS_GetClass(object)) {
- // Simply returns true if the object is this class's prototype object.
- // There is no need to return any value due to the object is not a platform
- // object. The execution reaches here when Object.getOwnPropertyDescriptor
- // gets called on native object prototypes.
- return true;
- }
-
- MozjsGlobalEnvironment* global_environment =
- static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context));
- WrapperFactory* wrapper_factory = global_environment->wrapper_factory();
- if (!wrapper_factory->DoesObjectImplementInterface(
- object, base::GetTypeId<AnonymousIndexedGetterInterface>())) {
- MozjsExceptionState exception(context);
- exception.SetSimpleException(script::kDoesNotImplementInterface);
- return false;
- }
- MozjsExceptionState exception_state(context);
- JS::RootedValue result_value(context);
-
- WrapperPrivate* wrapper_private =
- WrapperPrivate::GetFromObject(context, object);
- AnonymousIndexedGetterInterface* impl =
- wrapper_private->wrappable<AnonymousIndexedGetterInterface>().get();
-
- if (!exception_state.is_exception_set()) {
- ToJSValue(context,
- impl->length(),
- &result_value);
- }
- if (!exception_state.is_exception_set()) {
- vp.set(result_value);
- }
- return !exception_state.is_exception_set();
-}
-
-
-const JSPropertySpec prototype_properties[] = {
- { // Readonly attribute
- "length", 0,
- JSPROP_SHARED | JSPROP_ENUMERATE | JSPROP_READONLY,
- JSOP_WRAPPER(&get_length),
- JSOP_NULLWRAPPER,
- },
- JS_PS_END
-};
-
-const JSFunctionSpec prototype_functions[] = {
- JS_FS_END
-};
-
-const JSPropertySpec interface_object_properties[] = {
- JS_PS_END
-};
-
-const JSFunctionSpec interface_object_functions[] = {
- JS_FS_END
-};
-
-const JSPropertySpec own_properties[] = {
- JS_PS_END
-};
-
-void InitializePrototypeAndInterfaceObject(
- InterfaceData* interface_data, JSContext* context,
- JS::HandleObject global_object) {
- DCHECK(!interface_data->prototype);
- DCHECK(!interface_data->interface_object);
- DCHECK(JS_IsGlobalObject(global_object));
-
- JS::RootedObject parent_prototype(
- context, JS_GetObjectPrototype(context, global_object));
- DCHECK(parent_prototype);
-
- // Create the Prototype object.
- interface_data->prototype = JS_NewObjectWithGivenProto(
- context, &interface_data->prototype_class_definition, parent_prototype,
- NULL);
- bool success = JS_DefineProperties(
- context, interface_data->prototype, prototype_properties);
- DCHECK(success);
- success = JS_DefineFunctions(
- context, interface_data->prototype, prototype_functions);
- DCHECK(success);
-
- JS::RootedObject function_prototype(
- context, JS_GetFunctionPrototype(context, global_object));
- DCHECK(function_prototype);
- // Create the Interface object.
- interface_data->interface_object = JS_NewObjectWithGivenProto(
- context, &interface_data->interface_object_class_definition,
- function_prototype, NULL);
-
- // Add the InterfaceObject.name property.
- JS::RootedObject rooted_interface_object(
- context, interface_data->interface_object);
- JS::RootedValue name_value(context);
- const char name[] =
- "AnonymousIndexedGetterInterface";
- name_value.setString(JS_NewStringCopyZ(context, name));
- success =
- JS_DefineProperty(context, rooted_interface_object, "name", name_value,
- JS_PropertyStub, JS_StrictPropertyStub,
- JSPROP_READONLY);
- DCHECK(success);
-
- // Define interface object properties (including constants).
- success = JS_DefineProperties(context, rooted_interface_object,
- interface_object_properties);
- DCHECK(success);
- // Define interface object functions (static).
- success = JS_DefineFunctions(context, rooted_interface_object,
- interface_object_functions);
- DCHECK(success);
-
-
- // Set the Prototype.constructor and Constructor.prototype properties.
- DCHECK(interface_data->interface_object);
- DCHECK(interface_data->prototype);
- JS::RootedObject rooted_prototype(context, interface_data->prototype);
- success = JS_LinkConstructorAndPrototype(
- context,
- rooted_interface_object,
- rooted_prototype);
- DCHECK(success);
-}
-
-InterfaceData* GetInterfaceData(JSContext* context) {
- MozjsGlobalEnvironment* global_environment =
- static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context));
- // Use the address of the properties definition for this interface as a
- // unique key for looking up the InterfaceData for this interface.
- intptr_t key = reinterpret_cast<intptr_t>(&own_properties);
- InterfaceData* interface_data = global_environment->GetInterfaceData(key);
- if (!interface_data) {
- interface_data = CreateCachedInterfaceData();
- DCHECK(interface_data);
- global_environment->CacheInterfaceData(key, interface_data);
- DCHECK_EQ(interface_data, global_environment->GetInterfaceData(key));
- }
- return interface_data;
-}
-
-} // namespace
-
-// static
-JSObject* MozjsAnonymousIndexedGetterInterface::CreateProxy(
- JSContext* context, const scoped_refptr<Wrappable>& wrappable) {
- DCHECK(MozjsGlobalEnvironment::GetFromContext(context));
- JS::RootedObject global_object(
- context,
- MozjsGlobalEnvironment::GetFromContext(context)->global_object());
- DCHECK(global_object);
-
- InterfaceData* interface_data = GetInterfaceData(context);
- JS::RootedObject prototype(context, GetPrototype(context, global_object));
- DCHECK(prototype);
- JS::RootedObject new_object(context, JS_NewObjectWithGivenProto(
- context, &interface_data->instance_class_definition, prototype, NULL));
- DCHECK(new_object);
- JS::RootedObject proxy(context,
- ProxyHandler::NewProxy(context, new_object, prototype, NULL,
- proxy_handler.Pointer()));
- WrapperPrivate::AddPrivateData(context, proxy, wrappable);
- return proxy;
-}
-
-//static
-const JSClass* MozjsAnonymousIndexedGetterInterface::PrototypeClass(
- JSContext* context) {
- DCHECK(MozjsGlobalEnvironment::GetFromContext(context));
- JS::RootedObject global_object(
- context,
- MozjsGlobalEnvironment::GetFromContext(context)->global_object());
- DCHECK(global_object);
-
- JS::RootedObject prototype(context, GetPrototype(context, global_object));
- JSClass* proto_class = JS_GetClass(*prototype.address());
- return proto_class;
-}
-
-// static
-JSObject* MozjsAnonymousIndexedGetterInterface::GetPrototype(
- JSContext* context, JS::HandleObject global_object) {
- DCHECK(JS_IsGlobalObject(global_object));
-
- InterfaceData* interface_data = GetInterfaceData(context);
- if (!interface_data->prototype) {
- // Create new prototype that has all the props and methods
- InitializePrototypeAndInterfaceObject(
- interface_data, context, global_object);
- }
- DCHECK(interface_data->prototype);
- return interface_data->prototype;
-}
-
-// static
-JSObject* MozjsAnonymousIndexedGetterInterface::GetInterfaceObject(
- JSContext* context, JS::HandleObject global_object) {
- DCHECK(JS_IsGlobalObject(global_object));
-
- InterfaceData* interface_data = GetInterfaceData(context);
- if (!interface_data->interface_object) {
- InitializePrototypeAndInterfaceObject(
- interface_data, context, global_object);
- }
- DCHECK(interface_data->interface_object);
- return interface_data->interface_object;
-}
-
-
-namespace {
-} // namespace
-
-
-} // namespace testing
-} // namespace bindings
-} // namespace cobalt
diff --git a/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_anonymous_indexed_getter_interface.h b/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_anonymous_indexed_getter_interface.h
deleted file mode 100644
index e00f429..0000000
--- a/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_anonymous_indexed_getter_interface.h
+++ /dev/null
@@ -1,52 +0,0 @@
-// Copyright 2017 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/mozjs/templates/interface.h.template
-
-#ifndef MozjsAnonymousIndexedGetterInterface_h
-#define MozjsAnonymousIndexedGetterInterface_h
-
-#include "base/hash_tables.h"
-#include "base/lazy_instance.h"
-#include "base/memory/ref_counted.h"
-#include "base/threading/thread_checker.h"
-#include "cobalt/base/polymorphic_downcast.h"
-#include "cobalt/script/wrappable.h"
-#include "cobalt/bindings/testing/anonymous_indexed_getter_interface.h"
-
-#include "third_party/mozjs/js/src/jsapi.h"
-
-namespace cobalt {
-namespace bindings {
-namespace testing {
-
-class MozjsAnonymousIndexedGetterInterface {
- public:
- static JSObject* CreateProxy(JSContext* context,
- const scoped_refptr<script::Wrappable>& wrappable);
- static const JSClass* PrototypeClass(JSContext* context);
- static JSObject* GetPrototype(JSContext* context,
- JS::HandleObject global_object);
- static JSObject* GetInterfaceObject(JSContext* context,
- JS::HandleObject global_object);
-};
-
-} // namespace testing
-} // namespace bindings
-} // namespace cobalt
-
-#endif // MozjsAnonymousIndexedGetterInterface_h
diff --git a/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_anonymous_named_getter_interface.cc b/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_anonymous_named_getter_interface.cc
deleted file mode 100644
index a0d23a1..0000000
--- a/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_anonymous_named_getter_interface.cc
+++ /dev/null
@@ -1,461 +0,0 @@
-// Copyright 2017 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/mozjs/templates/interface.cc.template
-
-#include "cobalt/bindings/testing/mozjs_anonymous_named_getter_interface.h"
-
-#include "base/debug/trace_event.h"
-#include "cobalt/base/polymorphic_downcast.h"
-#include "cobalt/script/global_environment.h"
-#include "cobalt/script/opaque_handle.h"
-#include "cobalt/script/script_value.h"
-
-#include "mozjs_gen_type_conversion.h"
-
-#include "base/lazy_instance.h"
-#include "cobalt/script/exception_state.h"
-#include "cobalt/script/mozjs/callback_function_conversion.h"
-#include "cobalt/script/mozjs/conversion_helpers.h"
-#include "cobalt/script/mozjs/mozjs_callback_function.h"
-#include "cobalt/script/mozjs/mozjs_exception_state.h"
-#include "cobalt/script/mozjs/mozjs_global_environment.h"
-#include "cobalt/script/mozjs/mozjs_object_handle.h"
-#include "cobalt/script/mozjs/mozjs_property_enumerator.h"
-#include "cobalt/script/mozjs/mozjs_user_object_holder.h"
-#include "cobalt/script/mozjs/mozjs_value_handle.h"
-#include "cobalt/script/mozjs/native_promise.h"
-#include "cobalt/script/mozjs/proxy_handler.h"
-#include "cobalt/script/mozjs/type_traits.h"
-#include "cobalt/script/mozjs/wrapper_factory.h"
-#include "cobalt/script/mozjs/wrapper_private.h"
-#include "cobalt/script/property_enumerator.h"
-#include "cobalt/script/sequence.h"
-#include "third_party/mozjs/js/src/jsapi.h"
-#include "third_party/mozjs/js/src/jsfriendapi.h"
-
-namespace {
-using cobalt::bindings::testing::AnonymousNamedGetterInterface;
-using cobalt::bindings::testing::MozjsAnonymousNamedGetterInterface;
-using cobalt::script::CallbackInterfaceTraits;
-using cobalt::script::GlobalEnvironment;
-using cobalt::script::OpaqueHandle;
-using cobalt::script::OpaqueHandleHolder;
-using cobalt::script::ScriptValue;
-using cobalt::script::ValueHandle;
-using cobalt::script::Wrappable;
-
-using cobalt::script::CallbackFunction;
-using cobalt::script::CallbackInterfaceTraits;
-using cobalt::script::ExceptionState;
-using cobalt::script::Wrappable;
-using cobalt::script::mozjs::FromJSValue;
-using cobalt::script::mozjs::InterfaceData;
-using cobalt::script::mozjs::MozjsCallbackFunction;
-using cobalt::script::mozjs::MozjsExceptionState;
-using cobalt::script::mozjs::MozjsGlobalEnvironment;
-using cobalt::script::mozjs::MozjsPropertyEnumerator;
-using cobalt::script::mozjs::MozjsUserObjectHolder;
-using cobalt::script::mozjs::ProxyHandler;
-using cobalt::script::mozjs::ToJSValue;
-using cobalt::script::mozjs::TypeTraits;
-using cobalt::script::mozjs::WrapperFactory;
-using cobalt::script::mozjs::WrapperPrivate;
-using cobalt::script::mozjs::kConversionFlagClamped;
-using cobalt::script::mozjs::kConversionFlagNullable;
-using cobalt::script::mozjs::kConversionFlagRestricted;
-using cobalt::script::mozjs::kConversionFlagTreatNullAsEmptyString;
-using cobalt::script::mozjs::kConversionFlagTreatUndefinedAsEmptyString;
-using cobalt::script::mozjs::kNoConversionFlags;
-} // namespace
-
-namespace cobalt {
-namespace bindings {
-namespace testing {
-
-namespace {
-
-bool IsSupportedNamedProperty(JSContext* context, JS::HandleObject object,
- const std::string& property_name) {
- WrapperPrivate* wrapper_private =
- WrapperPrivate::GetFromObject(context, object);
- AnonymousNamedGetterInterface* impl =
- wrapper_private->wrappable<AnonymousNamedGetterInterface>().get();
- return impl->CanQueryNamedProperty(property_name);
-}
-
-void EnumerateSupportedNames(JSContext* context, JS::HandleObject object,
- JS::AutoIdVector* properties) {
- WrapperPrivate* wrapper_private =
- WrapperPrivate::GetFromObject(context, object);
- AnonymousNamedGetterInterface* impl =
- wrapper_private->wrappable<AnonymousNamedGetterInterface>().get();
- MozjsPropertyEnumerator enumerator(context, properties);
- impl->EnumerateNamedProperties(&enumerator);
-}
-
-JSBool GetNamedProperty(
- JSContext* context, JS::HandleObject object, JS::HandleId id,
- JS::MutableHandleValue vp) {
- JS::RootedValue id_value(context);
- if (!JS_IdToValue(context, id, id_value.address())) {
- NOTREACHED();
- return false;
- }
-
- MozjsExceptionState exception_state(context);
- JS::RootedValue result_value(context);
-
- WrapperPrivate* wrapper_private =
- WrapperPrivate::GetFromObject(context, object);
- AnonymousNamedGetterInterface* impl =
- wrapper_private->wrappable<AnonymousNamedGetterInterface>().get();
- std::string property_name;
- FromJSValue(context, id_value, kNoConversionFlags, &exception_state,
- &property_name);
- if (exception_state.is_exception_set()) {
- // The ID should be an integer or a string, so we shouldn't have any
- // exceptions converting to string.
- NOTREACHED();
- return false;
- }
-
- if (!exception_state.is_exception_set()) {
- ToJSValue(context,
- impl->AnonymousNamedGetter(property_name),
- &result_value);
- }
- if (!exception_state.is_exception_set()) {
- vp.set(result_value);
- }
- return !exception_state.is_exception_set();
-}
-
-JSBool SetNamedProperty(
- JSContext* context, JS::HandleObject object, JS::HandleId id,
- JSBool strict, JS::MutableHandleValue vp) {
- JS::RootedValue id_value(context);
- if (!JS_IdToValue(context, id, id_value.address())) {
- NOTREACHED();
- return false;
- }
- MozjsExceptionState exception_state(context);
- JS::RootedValue result_value(context);
-
- WrapperPrivate* wrapper_private =
- WrapperPrivate::GetFromObject(context, object);
- AnonymousNamedGetterInterface* impl =
- wrapper_private->wrappable<AnonymousNamedGetterInterface>().get();
- std::string property_name;
- FromJSValue(context, id_value, kNoConversionFlags, &exception_state,
- &property_name);
- if (exception_state.is_exception_set()) {
- // The ID should be an integer or a string, so we shouldn't have any
- // exceptions converting to string.
- NOTREACHED();
- return false;
- }
- TypeTraits<std::string >::ConversionType value;
- FromJSValue(context, vp, kNoConversionFlags,
- &exception_state, &value);
- if (exception_state.is_exception_set()) {
- return false;
- }
-
- impl->AnonymousNamedSetter(property_name, value);
- result_value.set(JS::UndefinedHandleValue);
- return !exception_state.is_exception_set();
-}
-
-class MozjsAnonymousNamedGetterInterfaceHandler : public ProxyHandler {
- public:
- MozjsAnonymousNamedGetterInterfaceHandler()
- : ProxyHandler(indexed_property_hooks, named_property_hooks) {}
-
- private:
- static NamedPropertyHooks named_property_hooks;
- static IndexedPropertyHooks indexed_property_hooks;
-};
-
-ProxyHandler::NamedPropertyHooks
-MozjsAnonymousNamedGetterInterfaceHandler::named_property_hooks = {
- IsSupportedNamedProperty,
- EnumerateSupportedNames,
- GetNamedProperty,
- SetNamedProperty,
- NULL,
-};
-ProxyHandler::IndexedPropertyHooks
-MozjsAnonymousNamedGetterInterfaceHandler::indexed_property_hooks = {
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
-};
-
-static base::LazyInstance<MozjsAnonymousNamedGetterInterfaceHandler>
- proxy_handler;
-
-JSBool HasInstance(JSContext *context, JS::HandleObject type,
- JS::MutableHandleValue vp, JSBool *success) {
- JS::RootedObject global_object(
- context, JS_GetGlobalForObject(context, type));
- DCHECK(global_object);
-
- JS::RootedObject prototype(
- context, MozjsAnonymousNamedGetterInterface::GetPrototype(context, global_object));
-
- // |IsDelegate| walks the prototype chain of an object returning true if
- // .prototype is found.
- bool is_delegate;
- if (!IsDelegate(context, prototype, vp, &is_delegate)) {
- *success = false;
- return false;
- }
-
- *success = is_delegate;
- return true;
-}
-
-InterfaceData* CreateCachedInterfaceData() {
- InterfaceData* interface_data = new InterfaceData();
- memset(&interface_data->instance_class_definition, 0,
- sizeof(interface_data->instance_class_definition));
- memset(&interface_data->prototype_class_definition, 0,
- sizeof(interface_data->prototype_class_definition));
- memset(&interface_data->interface_object_class_definition, 0,
- sizeof(interface_data->interface_object_class_definition));
-
- JSClass* instance_class = &interface_data->instance_class_definition;
- const int kGlobalFlags = 0;
- instance_class->name = "AnonymousNamedGetterInterface";
- instance_class->flags = kGlobalFlags | JSCLASS_HAS_PRIVATE;
- instance_class->addProperty = JS_PropertyStub;
- instance_class->delProperty = JS_DeletePropertyStub;
- instance_class->getProperty = JS_PropertyStub;
- instance_class->setProperty = JS_StrictPropertyStub;
- instance_class->enumerate = JS_EnumerateStub;
- instance_class->resolve = JS_ResolveStub;
- instance_class->convert = JS_ConvertStub;
- // Function to be called before on object of this class is garbage collected.
- instance_class->finalize = &WrapperPrivate::Finalizer;
- // Called to trace objects that can be referenced from this object.
- instance_class->trace = &WrapperPrivate::Trace;
-
- JSClass* prototype_class = &interface_data->prototype_class_definition;
- prototype_class->name = "AnonymousNamedGetterInterfacePrototype";
- prototype_class->flags = 0;
- prototype_class->addProperty = JS_PropertyStub;
- prototype_class->delProperty = JS_DeletePropertyStub;
- prototype_class->getProperty = JS_PropertyStub;
- prototype_class->setProperty = JS_StrictPropertyStub;
- prototype_class->enumerate = JS_EnumerateStub;
- prototype_class->resolve = JS_ResolveStub;
- prototype_class->convert = JS_ConvertStub;
-
- JSClass* interface_object_class =
- &interface_data->interface_object_class_definition;
- interface_object_class->name = "AnonymousNamedGetterInterfaceConstructor";
- interface_object_class->flags = 0;
- interface_object_class->addProperty = JS_PropertyStub;
- interface_object_class->delProperty = JS_DeletePropertyStub;
- interface_object_class->getProperty = JS_PropertyStub;
- interface_object_class->setProperty = JS_StrictPropertyStub;
- interface_object_class->enumerate = JS_EnumerateStub;
- interface_object_class->resolve = JS_ResolveStub;
- interface_object_class->convert = JS_ConvertStub;
- interface_object_class->hasInstance = &HasInstance;
- return interface_data;
-}
-
-
-const JSPropertySpec prototype_properties[] = {
- JS_PS_END
-};
-
-const JSFunctionSpec prototype_functions[] = {
- JS_FS_END
-};
-
-const JSPropertySpec interface_object_properties[] = {
- JS_PS_END
-};
-
-const JSFunctionSpec interface_object_functions[] = {
- JS_FS_END
-};
-
-const JSPropertySpec own_properties[] = {
- JS_PS_END
-};
-
-void InitializePrototypeAndInterfaceObject(
- InterfaceData* interface_data, JSContext* context,
- JS::HandleObject global_object) {
- DCHECK(!interface_data->prototype);
- DCHECK(!interface_data->interface_object);
- DCHECK(JS_IsGlobalObject(global_object));
-
- JS::RootedObject parent_prototype(
- context, JS_GetObjectPrototype(context, global_object));
- DCHECK(parent_prototype);
-
- // Create the Prototype object.
- interface_data->prototype = JS_NewObjectWithGivenProto(
- context, &interface_data->prototype_class_definition, parent_prototype,
- NULL);
- bool success = JS_DefineProperties(
- context, interface_data->prototype, prototype_properties);
- DCHECK(success);
- success = JS_DefineFunctions(
- context, interface_data->prototype, prototype_functions);
- DCHECK(success);
-
- JS::RootedObject function_prototype(
- context, JS_GetFunctionPrototype(context, global_object));
- DCHECK(function_prototype);
- // Create the Interface object.
- interface_data->interface_object = JS_NewObjectWithGivenProto(
- context, &interface_data->interface_object_class_definition,
- function_prototype, NULL);
-
- // Add the InterfaceObject.name property.
- JS::RootedObject rooted_interface_object(
- context, interface_data->interface_object);
- JS::RootedValue name_value(context);
- const char name[] =
- "AnonymousNamedGetterInterface";
- name_value.setString(JS_NewStringCopyZ(context, name));
- success =
- JS_DefineProperty(context, rooted_interface_object, "name", name_value,
- JS_PropertyStub, JS_StrictPropertyStub,
- JSPROP_READONLY);
- DCHECK(success);
-
- // Define interface object properties (including constants).
- success = JS_DefineProperties(context, rooted_interface_object,
- interface_object_properties);
- DCHECK(success);
- // Define interface object functions (static).
- success = JS_DefineFunctions(context, rooted_interface_object,
- interface_object_functions);
- DCHECK(success);
-
-
- // Set the Prototype.constructor and Constructor.prototype properties.
- DCHECK(interface_data->interface_object);
- DCHECK(interface_data->prototype);
- JS::RootedObject rooted_prototype(context, interface_data->prototype);
- success = JS_LinkConstructorAndPrototype(
- context,
- rooted_interface_object,
- rooted_prototype);
- DCHECK(success);
-}
-
-InterfaceData* GetInterfaceData(JSContext* context) {
- MozjsGlobalEnvironment* global_environment =
- static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context));
- // Use the address of the properties definition for this interface as a
- // unique key for looking up the InterfaceData for this interface.
- intptr_t key = reinterpret_cast<intptr_t>(&own_properties);
- InterfaceData* interface_data = global_environment->GetInterfaceData(key);
- if (!interface_data) {
- interface_data = CreateCachedInterfaceData();
- DCHECK(interface_data);
- global_environment->CacheInterfaceData(key, interface_data);
- DCHECK_EQ(interface_data, global_environment->GetInterfaceData(key));
- }
- return interface_data;
-}
-
-} // namespace
-
-// static
-JSObject* MozjsAnonymousNamedGetterInterface::CreateProxy(
- JSContext* context, const scoped_refptr<Wrappable>& wrappable) {
- DCHECK(MozjsGlobalEnvironment::GetFromContext(context));
- JS::RootedObject global_object(
- context,
- MozjsGlobalEnvironment::GetFromContext(context)->global_object());
- DCHECK(global_object);
-
- InterfaceData* interface_data = GetInterfaceData(context);
- JS::RootedObject prototype(context, GetPrototype(context, global_object));
- DCHECK(prototype);
- JS::RootedObject new_object(context, JS_NewObjectWithGivenProto(
- context, &interface_data->instance_class_definition, prototype, NULL));
- DCHECK(new_object);
- JS::RootedObject proxy(context,
- ProxyHandler::NewProxy(context, new_object, prototype, NULL,
- proxy_handler.Pointer()));
- WrapperPrivate::AddPrivateData(context, proxy, wrappable);
- return proxy;
-}
-
-//static
-const JSClass* MozjsAnonymousNamedGetterInterface::PrototypeClass(
- JSContext* context) {
- DCHECK(MozjsGlobalEnvironment::GetFromContext(context));
- JS::RootedObject global_object(
- context,
- MozjsGlobalEnvironment::GetFromContext(context)->global_object());
- DCHECK(global_object);
-
- JS::RootedObject prototype(context, GetPrototype(context, global_object));
- JSClass* proto_class = JS_GetClass(*prototype.address());
- return proto_class;
-}
-
-// static
-JSObject* MozjsAnonymousNamedGetterInterface::GetPrototype(
- JSContext* context, JS::HandleObject global_object) {
- DCHECK(JS_IsGlobalObject(global_object));
-
- InterfaceData* interface_data = GetInterfaceData(context);
- if (!interface_data->prototype) {
- // Create new prototype that has all the props and methods
- InitializePrototypeAndInterfaceObject(
- interface_data, context, global_object);
- }
- DCHECK(interface_data->prototype);
- return interface_data->prototype;
-}
-
-// static
-JSObject* MozjsAnonymousNamedGetterInterface::GetInterfaceObject(
- JSContext* context, JS::HandleObject global_object) {
- DCHECK(JS_IsGlobalObject(global_object));
-
- InterfaceData* interface_data = GetInterfaceData(context);
- if (!interface_data->interface_object) {
- InitializePrototypeAndInterfaceObject(
- interface_data, context, global_object);
- }
- DCHECK(interface_data->interface_object);
- return interface_data->interface_object;
-}
-
-
-namespace {
-} // namespace
-
-
-} // namespace testing
-} // namespace bindings
-} // namespace cobalt
diff --git a/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_anonymous_named_getter_interface.h b/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_anonymous_named_getter_interface.h
deleted file mode 100644
index 4084d40..0000000
--- a/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_anonymous_named_getter_interface.h
+++ /dev/null
@@ -1,52 +0,0 @@
-// Copyright 2017 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/mozjs/templates/interface.h.template
-
-#ifndef MozjsAnonymousNamedGetterInterface_h
-#define MozjsAnonymousNamedGetterInterface_h
-
-#include "base/hash_tables.h"
-#include "base/lazy_instance.h"
-#include "base/memory/ref_counted.h"
-#include "base/threading/thread_checker.h"
-#include "cobalt/base/polymorphic_downcast.h"
-#include "cobalt/script/wrappable.h"
-#include "cobalt/bindings/testing/anonymous_named_getter_interface.h"
-
-#include "third_party/mozjs/js/src/jsapi.h"
-
-namespace cobalt {
-namespace bindings {
-namespace testing {
-
-class MozjsAnonymousNamedGetterInterface {
- public:
- static JSObject* CreateProxy(JSContext* context,
- const scoped_refptr<script::Wrappable>& wrappable);
- static const JSClass* PrototypeClass(JSContext* context);
- static JSObject* GetPrototype(JSContext* context,
- JS::HandleObject global_object);
- static JSObject* GetInterfaceObject(JSContext* context,
- JS::HandleObject global_object);
-};
-
-} // namespace testing
-} // namespace bindings
-} // namespace cobalt
-
-#endif // MozjsAnonymousNamedGetterInterface_h
diff --git a/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_anonymous_named_indexed_getter_interface.cc b/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_anonymous_named_indexed_getter_interface.cc
deleted file mode 100644
index 717863b..0000000
--- a/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_anonymous_named_indexed_getter_interface.cc
+++ /dev/null
@@ -1,599 +0,0 @@
-// Copyright 2017 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/mozjs/templates/interface.cc.template
-
-#include "cobalt/bindings/testing/mozjs_anonymous_named_indexed_getter_interface.h"
-
-#include "base/debug/trace_event.h"
-#include "cobalt/base/polymorphic_downcast.h"
-#include "cobalt/script/global_environment.h"
-#include "cobalt/script/opaque_handle.h"
-#include "cobalt/script/script_value.h"
-
-#include "mozjs_gen_type_conversion.h"
-
-#include "base/lazy_instance.h"
-#include "cobalt/script/exception_state.h"
-#include "cobalt/script/mozjs/callback_function_conversion.h"
-#include "cobalt/script/mozjs/conversion_helpers.h"
-#include "cobalt/script/mozjs/mozjs_callback_function.h"
-#include "cobalt/script/mozjs/mozjs_exception_state.h"
-#include "cobalt/script/mozjs/mozjs_global_environment.h"
-#include "cobalt/script/mozjs/mozjs_object_handle.h"
-#include "cobalt/script/mozjs/mozjs_property_enumerator.h"
-#include "cobalt/script/mozjs/mozjs_user_object_holder.h"
-#include "cobalt/script/mozjs/mozjs_value_handle.h"
-#include "cobalt/script/mozjs/native_promise.h"
-#include "cobalt/script/mozjs/proxy_handler.h"
-#include "cobalt/script/mozjs/type_traits.h"
-#include "cobalt/script/mozjs/wrapper_factory.h"
-#include "cobalt/script/mozjs/wrapper_private.h"
-#include "cobalt/script/property_enumerator.h"
-#include "cobalt/script/sequence.h"
-#include "third_party/mozjs/js/src/jsapi.h"
-#include "third_party/mozjs/js/src/jsfriendapi.h"
-
-namespace {
-using cobalt::bindings::testing::AnonymousNamedIndexedGetterInterface;
-using cobalt::bindings::testing::MozjsAnonymousNamedIndexedGetterInterface;
-using cobalt::script::CallbackInterfaceTraits;
-using cobalt::script::GlobalEnvironment;
-using cobalt::script::OpaqueHandle;
-using cobalt::script::OpaqueHandleHolder;
-using cobalt::script::ScriptValue;
-using cobalt::script::ValueHandle;
-using cobalt::script::Wrappable;
-
-using cobalt::script::CallbackFunction;
-using cobalt::script::CallbackInterfaceTraits;
-using cobalt::script::ExceptionState;
-using cobalt::script::Wrappable;
-using cobalt::script::mozjs::FromJSValue;
-using cobalt::script::mozjs::InterfaceData;
-using cobalt::script::mozjs::MozjsCallbackFunction;
-using cobalt::script::mozjs::MozjsExceptionState;
-using cobalt::script::mozjs::MozjsGlobalEnvironment;
-using cobalt::script::mozjs::MozjsPropertyEnumerator;
-using cobalt::script::mozjs::MozjsUserObjectHolder;
-using cobalt::script::mozjs::ProxyHandler;
-using cobalt::script::mozjs::ToJSValue;
-using cobalt::script::mozjs::TypeTraits;
-using cobalt::script::mozjs::WrapperFactory;
-using cobalt::script::mozjs::WrapperPrivate;
-using cobalt::script::mozjs::kConversionFlagClamped;
-using cobalt::script::mozjs::kConversionFlagNullable;
-using cobalt::script::mozjs::kConversionFlagRestricted;
-using cobalt::script::mozjs::kConversionFlagTreatNullAsEmptyString;
-using cobalt::script::mozjs::kConversionFlagTreatUndefinedAsEmptyString;
-using cobalt::script::mozjs::kNoConversionFlags;
-} // namespace
-
-namespace cobalt {
-namespace bindings {
-namespace testing {
-
-namespace {
-
-bool IsSupportedNamedProperty(JSContext* context, JS::HandleObject object,
- const std::string& property_name) {
- WrapperPrivate* wrapper_private =
- WrapperPrivate::GetFromObject(context, object);
- AnonymousNamedIndexedGetterInterface* impl =
- wrapper_private->wrappable<AnonymousNamedIndexedGetterInterface>().get();
- return impl->CanQueryNamedProperty(property_name);
-}
-
-void EnumerateSupportedNames(JSContext* context, JS::HandleObject object,
- JS::AutoIdVector* properties) {
- WrapperPrivate* wrapper_private =
- WrapperPrivate::GetFromObject(context, object);
- AnonymousNamedIndexedGetterInterface* impl =
- wrapper_private->wrappable<AnonymousNamedIndexedGetterInterface>().get();
- MozjsPropertyEnumerator enumerator(context, properties);
- impl->EnumerateNamedProperties(&enumerator);
-}
-
-JSBool GetNamedProperty(
- JSContext* context, JS::HandleObject object, JS::HandleId id,
- JS::MutableHandleValue vp) {
- JS::RootedValue id_value(context);
- if (!JS_IdToValue(context, id, id_value.address())) {
- NOTREACHED();
- return false;
- }
-
- MozjsExceptionState exception_state(context);
- JS::RootedValue result_value(context);
-
- WrapperPrivate* wrapper_private =
- WrapperPrivate::GetFromObject(context, object);
- AnonymousNamedIndexedGetterInterface* impl =
- wrapper_private->wrappable<AnonymousNamedIndexedGetterInterface>().get();
- std::string property_name;
- FromJSValue(context, id_value, kNoConversionFlags, &exception_state,
- &property_name);
- if (exception_state.is_exception_set()) {
- // The ID should be an integer or a string, so we shouldn't have any
- // exceptions converting to string.
- NOTREACHED();
- return false;
- }
-
- if (!exception_state.is_exception_set()) {
- ToJSValue(context,
- impl->AnonymousNamedGetter(property_name),
- &result_value);
- }
- if (!exception_state.is_exception_set()) {
- vp.set(result_value);
- }
- return !exception_state.is_exception_set();
-}
-
-JSBool SetNamedProperty(
- JSContext* context, JS::HandleObject object, JS::HandleId id,
- JSBool strict, JS::MutableHandleValue vp) {
- JS::RootedValue id_value(context);
- if (!JS_IdToValue(context, id, id_value.address())) {
- NOTREACHED();
- return false;
- }
- MozjsExceptionState exception_state(context);
- JS::RootedValue result_value(context);
-
- WrapperPrivate* wrapper_private =
- WrapperPrivate::GetFromObject(context, object);
- AnonymousNamedIndexedGetterInterface* impl =
- wrapper_private->wrappable<AnonymousNamedIndexedGetterInterface>().get();
- std::string property_name;
- FromJSValue(context, id_value, kNoConversionFlags, &exception_state,
- &property_name);
- if (exception_state.is_exception_set()) {
- // The ID should be an integer or a string, so we shouldn't have any
- // exceptions converting to string.
- NOTREACHED();
- return false;
- }
- TypeTraits<std::string >::ConversionType value;
- FromJSValue(context, vp, kNoConversionFlags,
- &exception_state, &value);
- if (exception_state.is_exception_set()) {
- return false;
- }
-
- impl->AnonymousNamedSetter(property_name, value);
- result_value.set(JS::UndefinedHandleValue);
- return !exception_state.is_exception_set();
-}
-
-bool IsSupportedIndexProperty(JSContext* context, JS::HandleObject object,
- uint32_t index) {
- WrapperPrivate* wrapper_private =
- WrapperPrivate::GetFromObject(context, object);
- AnonymousNamedIndexedGetterInterface* impl =
- wrapper_private->wrappable<AnonymousNamedIndexedGetterInterface>().get();
- return index < impl->length();
-}
-
-void EnumerateSupportedIndexes(JSContext* context, JS::HandleObject object,
- JS::AutoIdVector* properties) {
- WrapperPrivate* wrapper_private =
- WrapperPrivate::GetFromObject(context, object);
- AnonymousNamedIndexedGetterInterface* impl =
- wrapper_private->wrappable<AnonymousNamedIndexedGetterInterface>().get();
- const uint32_t kNumIndexedProperties = impl->length();
- for (uint32_t i = 0; i < kNumIndexedProperties; ++i) {
- properties->append(INT_TO_JSID(i));
- }
-}
-
-JSBool GetIndexedProperty(
- JSContext* context, JS::HandleObject object, JS::HandleId id,
- JS::MutableHandleValue vp) {
- JS::RootedValue id_value(context);
- if (!JS_IdToValue(context, id, id_value.address())) {
- NOTREACHED();
- return false;
- }
- MozjsExceptionState exception_state(context);
- JS::RootedValue result_value(context);
-
- WrapperPrivate* wrapper_private =
- WrapperPrivate::GetFromObject(context, object);
- AnonymousNamedIndexedGetterInterface* impl =
- wrapper_private->wrappable<AnonymousNamedIndexedGetterInterface>().get();
- uint32_t index;
- FromJSValue(context, id_value, kNoConversionFlags, &exception_state, &index);
- if (exception_state.is_exception_set()) {
- // The ID should be an integer or a string, so we shouldn't have any
- // exceptions converting to string.
- NOTREACHED();
- return false;
- }
-
- if (!exception_state.is_exception_set()) {
- ToJSValue(context,
- impl->AnonymousIndexedGetter(index),
- &result_value);
- }
- if (!exception_state.is_exception_set()) {
- vp.set(result_value);
- }
- return !exception_state.is_exception_set();
-}
-
-JSBool SetIndexedProperty(
- JSContext* context, JS::HandleObject object, JS::HandleId id,
- JSBool strict, JS::MutableHandleValue vp) {
- JS::RootedValue id_value(context);
- if (!JS_IdToValue(context, id, id_value.address())) {
- NOTREACHED();
- return false;
- }
- MozjsExceptionState exception_state(context);
- JS::RootedValue result_value(context);
-
- WrapperPrivate* wrapper_private =
- WrapperPrivate::GetFromObject(context, object);
- AnonymousNamedIndexedGetterInterface* impl =
- wrapper_private->wrappable<AnonymousNamedIndexedGetterInterface>().get();
- uint32_t index;
- FromJSValue(context, id_value, kNoConversionFlags, &exception_state, &index);
- if(exception_state.is_exception_set()) {
- // The ID should be an integer or a string, so we shouldn't have any
- // exceptions converting to string.
- NOTREACHED();
- return false;
- }
- TypeTraits<uint32_t >::ConversionType value;
- FromJSValue(context, vp, kNoConversionFlags,
- &exception_state, &value);
- if (exception_state.is_exception_set()) {
- return false;
- }
-
- impl->AnonymousIndexedSetter(index, value);
- result_value.set(JS::UndefinedHandleValue);
- return !exception_state.is_exception_set();
-}
-
-class MozjsAnonymousNamedIndexedGetterInterfaceHandler : public ProxyHandler {
- public:
- MozjsAnonymousNamedIndexedGetterInterfaceHandler()
- : ProxyHandler(indexed_property_hooks, named_property_hooks) {}
-
- private:
- static NamedPropertyHooks named_property_hooks;
- static IndexedPropertyHooks indexed_property_hooks;
-};
-
-ProxyHandler::NamedPropertyHooks
-MozjsAnonymousNamedIndexedGetterInterfaceHandler::named_property_hooks = {
- IsSupportedNamedProperty,
- EnumerateSupportedNames,
- GetNamedProperty,
- SetNamedProperty,
- NULL,
-};
-ProxyHandler::IndexedPropertyHooks
-MozjsAnonymousNamedIndexedGetterInterfaceHandler::indexed_property_hooks = {
- IsSupportedIndexProperty,
- EnumerateSupportedIndexes,
- GetIndexedProperty,
- SetIndexedProperty,
- NULL,
-};
-
-static base::LazyInstance<MozjsAnonymousNamedIndexedGetterInterfaceHandler>
- proxy_handler;
-
-JSBool HasInstance(JSContext *context, JS::HandleObject type,
- JS::MutableHandleValue vp, JSBool *success) {
- JS::RootedObject global_object(
- context, JS_GetGlobalForObject(context, type));
- DCHECK(global_object);
-
- JS::RootedObject prototype(
- context, MozjsAnonymousNamedIndexedGetterInterface::GetPrototype(context, global_object));
-
- // |IsDelegate| walks the prototype chain of an object returning true if
- // .prototype is found.
- bool is_delegate;
- if (!IsDelegate(context, prototype, vp, &is_delegate)) {
- *success = false;
- return false;
- }
-
- *success = is_delegate;
- return true;
-}
-
-InterfaceData* CreateCachedInterfaceData() {
- InterfaceData* interface_data = new InterfaceData();
- memset(&interface_data->instance_class_definition, 0,
- sizeof(interface_data->instance_class_definition));
- memset(&interface_data->prototype_class_definition, 0,
- sizeof(interface_data->prototype_class_definition));
- memset(&interface_data->interface_object_class_definition, 0,
- sizeof(interface_data->interface_object_class_definition));
-
- JSClass* instance_class = &interface_data->instance_class_definition;
- const int kGlobalFlags = 0;
- instance_class->name = "AnonymousNamedIndexedGetterInterface";
- instance_class->flags = kGlobalFlags | JSCLASS_HAS_PRIVATE;
- instance_class->addProperty = JS_PropertyStub;
- instance_class->delProperty = JS_DeletePropertyStub;
- instance_class->getProperty = JS_PropertyStub;
- instance_class->setProperty = JS_StrictPropertyStub;
- instance_class->enumerate = JS_EnumerateStub;
- instance_class->resolve = JS_ResolveStub;
- instance_class->convert = JS_ConvertStub;
- // Function to be called before on object of this class is garbage collected.
- instance_class->finalize = &WrapperPrivate::Finalizer;
- // Called to trace objects that can be referenced from this object.
- instance_class->trace = &WrapperPrivate::Trace;
-
- JSClass* prototype_class = &interface_data->prototype_class_definition;
- prototype_class->name = "AnonymousNamedIndexedGetterInterfacePrototype";
- prototype_class->flags = 0;
- prototype_class->addProperty = JS_PropertyStub;
- prototype_class->delProperty = JS_DeletePropertyStub;
- prototype_class->getProperty = JS_PropertyStub;
- prototype_class->setProperty = JS_StrictPropertyStub;
- prototype_class->enumerate = JS_EnumerateStub;
- prototype_class->resolve = JS_ResolveStub;
- prototype_class->convert = JS_ConvertStub;
-
- JSClass* interface_object_class =
- &interface_data->interface_object_class_definition;
- interface_object_class->name = "AnonymousNamedIndexedGetterInterfaceConstructor";
- interface_object_class->flags = 0;
- interface_object_class->addProperty = JS_PropertyStub;
- interface_object_class->delProperty = JS_DeletePropertyStub;
- interface_object_class->getProperty = JS_PropertyStub;
- interface_object_class->setProperty = JS_StrictPropertyStub;
- interface_object_class->enumerate = JS_EnumerateStub;
- interface_object_class->resolve = JS_ResolveStub;
- interface_object_class->convert = JS_ConvertStub;
- interface_object_class->hasInstance = &HasInstance;
- return interface_data;
-}
-
-JSBool get_length(
- JSContext* context, JS::HandleObject object, JS::HandleId id,
- JS::MutableHandleValue vp) {
- const JSClass* proto_class =
- MozjsAnonymousNamedIndexedGetterInterface::PrototypeClass(context);
- if (proto_class == JS_GetClass(object)) {
- // Simply returns true if the object is this class's prototype object.
- // There is no need to return any value due to the object is not a platform
- // object. The execution reaches here when Object.getOwnPropertyDescriptor
- // gets called on native object prototypes.
- return true;
- }
-
- MozjsGlobalEnvironment* global_environment =
- static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context));
- WrapperFactory* wrapper_factory = global_environment->wrapper_factory();
- if (!wrapper_factory->DoesObjectImplementInterface(
- object, base::GetTypeId<AnonymousNamedIndexedGetterInterface>())) {
- MozjsExceptionState exception(context);
- exception.SetSimpleException(script::kDoesNotImplementInterface);
- return false;
- }
- MozjsExceptionState exception_state(context);
- JS::RootedValue result_value(context);
-
- WrapperPrivate* wrapper_private =
- WrapperPrivate::GetFromObject(context, object);
- AnonymousNamedIndexedGetterInterface* impl =
- wrapper_private->wrappable<AnonymousNamedIndexedGetterInterface>().get();
-
- if (!exception_state.is_exception_set()) {
- ToJSValue(context,
- impl->length(),
- &result_value);
- }
- if (!exception_state.is_exception_set()) {
- vp.set(result_value);
- }
- return !exception_state.is_exception_set();
-}
-
-
-const JSPropertySpec prototype_properties[] = {
- { // Readonly attribute
- "length", 0,
- JSPROP_SHARED | JSPROP_ENUMERATE | JSPROP_READONLY,
- JSOP_WRAPPER(&get_length),
- JSOP_NULLWRAPPER,
- },
- JS_PS_END
-};
-
-const JSFunctionSpec prototype_functions[] = {
- JS_FS_END
-};
-
-const JSPropertySpec interface_object_properties[] = {
- JS_PS_END
-};
-
-const JSFunctionSpec interface_object_functions[] = {
- JS_FS_END
-};
-
-const JSPropertySpec own_properties[] = {
- JS_PS_END
-};
-
-void InitializePrototypeAndInterfaceObject(
- InterfaceData* interface_data, JSContext* context,
- JS::HandleObject global_object) {
- DCHECK(!interface_data->prototype);
- DCHECK(!interface_data->interface_object);
- DCHECK(JS_IsGlobalObject(global_object));
-
- JS::RootedObject parent_prototype(
- context, JS_GetObjectPrototype(context, global_object));
- DCHECK(parent_prototype);
-
- // Create the Prototype object.
- interface_data->prototype = JS_NewObjectWithGivenProto(
- context, &interface_data->prototype_class_definition, parent_prototype,
- NULL);
- bool success = JS_DefineProperties(
- context, interface_data->prototype, prototype_properties);
- DCHECK(success);
- success = JS_DefineFunctions(
- context, interface_data->prototype, prototype_functions);
- DCHECK(success);
-
- JS::RootedObject function_prototype(
- context, JS_GetFunctionPrototype(context, global_object));
- DCHECK(function_prototype);
- // Create the Interface object.
- interface_data->interface_object = JS_NewObjectWithGivenProto(
- context, &interface_data->interface_object_class_definition,
- function_prototype, NULL);
-
- // Add the InterfaceObject.name property.
- JS::RootedObject rooted_interface_object(
- context, interface_data->interface_object);
- JS::RootedValue name_value(context);
- const char name[] =
- "AnonymousNamedIndexedGetterInterface";
- name_value.setString(JS_NewStringCopyZ(context, name));
- success =
- JS_DefineProperty(context, rooted_interface_object, "name", name_value,
- JS_PropertyStub, JS_StrictPropertyStub,
- JSPROP_READONLY);
- DCHECK(success);
-
- // Define interface object properties (including constants).
- success = JS_DefineProperties(context, rooted_interface_object,
- interface_object_properties);
- DCHECK(success);
- // Define interface object functions (static).
- success = JS_DefineFunctions(context, rooted_interface_object,
- interface_object_functions);
- DCHECK(success);
-
-
- // Set the Prototype.constructor and Constructor.prototype properties.
- DCHECK(interface_data->interface_object);
- DCHECK(interface_data->prototype);
- JS::RootedObject rooted_prototype(context, interface_data->prototype);
- success = JS_LinkConstructorAndPrototype(
- context,
- rooted_interface_object,
- rooted_prototype);
- DCHECK(success);
-}
-
-InterfaceData* GetInterfaceData(JSContext* context) {
- MozjsGlobalEnvironment* global_environment =
- static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context));
- // Use the address of the properties definition for this interface as a
- // unique key for looking up the InterfaceData for this interface.
- intptr_t key = reinterpret_cast<intptr_t>(&own_properties);
- InterfaceData* interface_data = global_environment->GetInterfaceData(key);
- if (!interface_data) {
- interface_data = CreateCachedInterfaceData();
- DCHECK(interface_data);
- global_environment->CacheInterfaceData(key, interface_data);
- DCHECK_EQ(interface_data, global_environment->GetInterfaceData(key));
- }
- return interface_data;
-}
-
-} // namespace
-
-// static
-JSObject* MozjsAnonymousNamedIndexedGetterInterface::CreateProxy(
- JSContext* context, const scoped_refptr<Wrappable>& wrappable) {
- DCHECK(MozjsGlobalEnvironment::GetFromContext(context));
- JS::RootedObject global_object(
- context,
- MozjsGlobalEnvironment::GetFromContext(context)->global_object());
- DCHECK(global_object);
-
- InterfaceData* interface_data = GetInterfaceData(context);
- JS::RootedObject prototype(context, GetPrototype(context, global_object));
- DCHECK(prototype);
- JS::RootedObject new_object(context, JS_NewObjectWithGivenProto(
- context, &interface_data->instance_class_definition, prototype, NULL));
- DCHECK(new_object);
- JS::RootedObject proxy(context,
- ProxyHandler::NewProxy(context, new_object, prototype, NULL,
- proxy_handler.Pointer()));
- WrapperPrivate::AddPrivateData(context, proxy, wrappable);
- return proxy;
-}
-
-//static
-const JSClass* MozjsAnonymousNamedIndexedGetterInterface::PrototypeClass(
- JSContext* context) {
- DCHECK(MozjsGlobalEnvironment::GetFromContext(context));
- JS::RootedObject global_object(
- context,
- MozjsGlobalEnvironment::GetFromContext(context)->global_object());
- DCHECK(global_object);
-
- JS::RootedObject prototype(context, GetPrototype(context, global_object));
- JSClass* proto_class = JS_GetClass(*prototype.address());
- return proto_class;
-}
-
-// static
-JSObject* MozjsAnonymousNamedIndexedGetterInterface::GetPrototype(
- JSContext* context, JS::HandleObject global_object) {
- DCHECK(JS_IsGlobalObject(global_object));
-
- InterfaceData* interface_data = GetInterfaceData(context);
- if (!interface_data->prototype) {
- // Create new prototype that has all the props and methods
- InitializePrototypeAndInterfaceObject(
- interface_data, context, global_object);
- }
- DCHECK(interface_data->prototype);
- return interface_data->prototype;
-}
-
-// static
-JSObject* MozjsAnonymousNamedIndexedGetterInterface::GetInterfaceObject(
- JSContext* context, JS::HandleObject global_object) {
- DCHECK(JS_IsGlobalObject(global_object));
-
- InterfaceData* interface_data = GetInterfaceData(context);
- if (!interface_data->interface_object) {
- InitializePrototypeAndInterfaceObject(
- interface_data, context, global_object);
- }
- DCHECK(interface_data->interface_object);
- return interface_data->interface_object;
-}
-
-
-namespace {
-} // namespace
-
-
-} // namespace testing
-} // namespace bindings
-} // namespace cobalt
diff --git a/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_anonymous_named_indexed_getter_interface.h b/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_anonymous_named_indexed_getter_interface.h
deleted file mode 100644
index c615c45..0000000
--- a/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_anonymous_named_indexed_getter_interface.h
+++ /dev/null
@@ -1,52 +0,0 @@
-// Copyright 2017 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/mozjs/templates/interface.h.template
-
-#ifndef MozjsAnonymousNamedIndexedGetterInterface_h
-#define MozjsAnonymousNamedIndexedGetterInterface_h
-
-#include "base/hash_tables.h"
-#include "base/lazy_instance.h"
-#include "base/memory/ref_counted.h"
-#include "base/threading/thread_checker.h"
-#include "cobalt/base/polymorphic_downcast.h"
-#include "cobalt/script/wrappable.h"
-#include "cobalt/bindings/testing/anonymous_named_indexed_getter_interface.h"
-
-#include "third_party/mozjs/js/src/jsapi.h"
-
-namespace cobalt {
-namespace bindings {
-namespace testing {
-
-class MozjsAnonymousNamedIndexedGetterInterface {
- public:
- static JSObject* CreateProxy(JSContext* context,
- const scoped_refptr<script::Wrappable>& wrappable);
- static const JSClass* PrototypeClass(JSContext* context);
- static JSObject* GetPrototype(JSContext* context,
- JS::HandleObject global_object);
- static JSObject* GetInterfaceObject(JSContext* context,
- JS::HandleObject global_object);
-};
-
-} // namespace testing
-} // namespace bindings
-} // namespace cobalt
-
-#endif // MozjsAnonymousNamedIndexedGetterInterface_h
diff --git a/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_arbitrary_interface.cc b/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_arbitrary_interface.cc
deleted file mode 100644
index 9c7df9d..0000000
--- a/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_arbitrary_interface.cc
+++ /dev/null
@@ -1,535 +0,0 @@
-// Copyright 2017 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/mozjs/templates/interface.cc.template
-
-#include "cobalt/bindings/testing/mozjs_arbitrary_interface.h"
-
-#include "base/debug/trace_event.h"
-#include "cobalt/base/polymorphic_downcast.h"
-#include "cobalt/script/global_environment.h"
-#include "cobalt/script/opaque_handle.h"
-#include "cobalt/script/script_value.h"
-
-#include "mozjs_gen_type_conversion.h"
-
-#include "base/lazy_instance.h"
-#include "cobalt/script/exception_state.h"
-#include "cobalt/script/mozjs/callback_function_conversion.h"
-#include "cobalt/script/mozjs/conversion_helpers.h"
-#include "cobalt/script/mozjs/mozjs_callback_function.h"
-#include "cobalt/script/mozjs/mozjs_exception_state.h"
-#include "cobalt/script/mozjs/mozjs_global_environment.h"
-#include "cobalt/script/mozjs/mozjs_object_handle.h"
-#include "cobalt/script/mozjs/mozjs_property_enumerator.h"
-#include "cobalt/script/mozjs/mozjs_user_object_holder.h"
-#include "cobalt/script/mozjs/mozjs_value_handle.h"
-#include "cobalt/script/mozjs/native_promise.h"
-#include "cobalt/script/mozjs/proxy_handler.h"
-#include "cobalt/script/mozjs/type_traits.h"
-#include "cobalt/script/mozjs/wrapper_factory.h"
-#include "cobalt/script/mozjs/wrapper_private.h"
-#include "cobalt/script/property_enumerator.h"
-#include "cobalt/script/sequence.h"
-#include "third_party/mozjs/js/src/jsapi.h"
-#include "third_party/mozjs/js/src/jsfriendapi.h"
-
-namespace {
-using cobalt::bindings::testing::ArbitraryInterface;
-using cobalt::bindings::testing::MozjsArbitraryInterface;
-using cobalt::script::CallbackInterfaceTraits;
-using cobalt::script::GlobalEnvironment;
-using cobalt::script::OpaqueHandle;
-using cobalt::script::OpaqueHandleHolder;
-using cobalt::script::ScriptValue;
-using cobalt::script::ValueHandle;
-using cobalt::script::Wrappable;
-
-using cobalt::script::CallbackFunction;
-using cobalt::script::CallbackInterfaceTraits;
-using cobalt::script::ExceptionState;
-using cobalt::script::Wrappable;
-using cobalt::script::mozjs::FromJSValue;
-using cobalt::script::mozjs::InterfaceData;
-using cobalt::script::mozjs::MozjsCallbackFunction;
-using cobalt::script::mozjs::MozjsExceptionState;
-using cobalt::script::mozjs::MozjsGlobalEnvironment;
-using cobalt::script::mozjs::MozjsPropertyEnumerator;
-using cobalt::script::mozjs::MozjsUserObjectHolder;
-using cobalt::script::mozjs::ProxyHandler;
-using cobalt::script::mozjs::ToJSValue;
-using cobalt::script::mozjs::TypeTraits;
-using cobalt::script::mozjs::WrapperFactory;
-using cobalt::script::mozjs::WrapperPrivate;
-using cobalt::script::mozjs::kConversionFlagClamped;
-using cobalt::script::mozjs::kConversionFlagNullable;
-using cobalt::script::mozjs::kConversionFlagRestricted;
-using cobalt::script::mozjs::kConversionFlagTreatNullAsEmptyString;
-using cobalt::script::mozjs::kConversionFlagTreatUndefinedAsEmptyString;
-using cobalt::script::mozjs::kNoConversionFlags;
-} // namespace
-
-namespace cobalt {
-namespace bindings {
-namespace testing {
-
-namespace {
-
-class MozjsArbitraryInterfaceHandler : public ProxyHandler {
- public:
- MozjsArbitraryInterfaceHandler()
- : ProxyHandler(indexed_property_hooks, named_property_hooks) {}
-
- private:
- static NamedPropertyHooks named_property_hooks;
- static IndexedPropertyHooks indexed_property_hooks;
-};
-
-ProxyHandler::NamedPropertyHooks
-MozjsArbitraryInterfaceHandler::named_property_hooks = {
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
-};
-ProxyHandler::IndexedPropertyHooks
-MozjsArbitraryInterfaceHandler::indexed_property_hooks = {
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
-};
-
-static base::LazyInstance<MozjsArbitraryInterfaceHandler>
- proxy_handler;
-
-JSBool Constructor(JSContext* context, unsigned int argc, JS::Value* vp);
-JSBool HasInstance(JSContext *context, JS::HandleObject type,
- JS::MutableHandleValue vp, JSBool *success) {
- JS::RootedObject global_object(
- context, JS_GetGlobalForObject(context, type));
- DCHECK(global_object);
-
- JS::RootedObject prototype(
- context, MozjsArbitraryInterface::GetPrototype(context, global_object));
-
- // |IsDelegate| walks the prototype chain of an object returning true if
- // .prototype is found.
- bool is_delegate;
- if (!IsDelegate(context, prototype, vp, &is_delegate)) {
- *success = false;
- return false;
- }
-
- *success = is_delegate;
- return true;
-}
-
-InterfaceData* CreateCachedInterfaceData() {
- InterfaceData* interface_data = new InterfaceData();
- memset(&interface_data->instance_class_definition, 0,
- sizeof(interface_data->instance_class_definition));
- memset(&interface_data->prototype_class_definition, 0,
- sizeof(interface_data->prototype_class_definition));
- memset(&interface_data->interface_object_class_definition, 0,
- sizeof(interface_data->interface_object_class_definition));
-
- JSClass* instance_class = &interface_data->instance_class_definition;
- const int kGlobalFlags = 0;
- instance_class->name = "ArbitraryInterface";
- instance_class->flags = kGlobalFlags | JSCLASS_HAS_PRIVATE;
- instance_class->addProperty = JS_PropertyStub;
- instance_class->delProperty = JS_DeletePropertyStub;
- instance_class->getProperty = JS_PropertyStub;
- instance_class->setProperty = JS_StrictPropertyStub;
- instance_class->enumerate = JS_EnumerateStub;
- instance_class->resolve = JS_ResolveStub;
- instance_class->convert = JS_ConvertStub;
- // Function to be called before on object of this class is garbage collected.
- instance_class->finalize = &WrapperPrivate::Finalizer;
- // Called to trace objects that can be referenced from this object.
- instance_class->trace = &WrapperPrivate::Trace;
-
- JSClass* prototype_class = &interface_data->prototype_class_definition;
- prototype_class->name = "ArbitraryInterfacePrototype";
- prototype_class->flags = 0;
- prototype_class->addProperty = JS_PropertyStub;
- prototype_class->delProperty = JS_DeletePropertyStub;
- prototype_class->getProperty = JS_PropertyStub;
- prototype_class->setProperty = JS_StrictPropertyStub;
- prototype_class->enumerate = JS_EnumerateStub;
- prototype_class->resolve = JS_ResolveStub;
- prototype_class->convert = JS_ConvertStub;
-
- JSClass* interface_object_class =
- &interface_data->interface_object_class_definition;
- interface_object_class->name = "ArbitraryInterfaceConstructor";
- interface_object_class->flags = 0;
- interface_object_class->addProperty = JS_PropertyStub;
- interface_object_class->delProperty = JS_DeletePropertyStub;
- interface_object_class->getProperty = JS_PropertyStub;
- interface_object_class->setProperty = JS_StrictPropertyStub;
- interface_object_class->enumerate = JS_EnumerateStub;
- interface_object_class->resolve = JS_ResolveStub;
- interface_object_class->convert = JS_ConvertStub;
- interface_object_class->hasInstance = &HasInstance;
- interface_object_class->construct = Constructor;
- return interface_data;
-}
-
-JSBool get_arbitraryProperty(
- JSContext* context, JS::HandleObject object, JS::HandleId id,
- JS::MutableHandleValue vp) {
- const JSClass* proto_class =
- MozjsArbitraryInterface::PrototypeClass(context);
- if (proto_class == JS_GetClass(object)) {
- // Simply returns true if the object is this class's prototype object.
- // There is no need to return any value due to the object is not a platform
- // object. The execution reaches here when Object.getOwnPropertyDescriptor
- // gets called on native object prototypes.
- return true;
- }
-
- MozjsGlobalEnvironment* global_environment =
- static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context));
- WrapperFactory* wrapper_factory = global_environment->wrapper_factory();
- if (!wrapper_factory->DoesObjectImplementInterface(
- object, base::GetTypeId<ArbitraryInterface>())) {
- MozjsExceptionState exception(context);
- exception.SetSimpleException(script::kDoesNotImplementInterface);
- return false;
- }
- MozjsExceptionState exception_state(context);
- JS::RootedValue result_value(context);
-
- WrapperPrivate* wrapper_private =
- WrapperPrivate::GetFromObject(context, object);
- ArbitraryInterface* impl =
- wrapper_private->wrappable<ArbitraryInterface>().get();
-
- if (!exception_state.is_exception_set()) {
- ToJSValue(context,
- impl->arbitrary_property(),
- &result_value);
- }
- if (!exception_state.is_exception_set()) {
- vp.set(result_value);
- }
- return !exception_state.is_exception_set();
-}
-
-JSBool set_arbitraryProperty(
- JSContext* context, JS::HandleObject object, JS::HandleId id,
- JSBool strict, JS::MutableHandleValue vp) {
- const JSClass* proto_class =
- MozjsArbitraryInterface::PrototypeClass(context);
- if (proto_class == JS_GetClass(object)) {
- // Simply returns true if the object is this class's prototype object.
- // There is no need to return any value due to the object is not a platform
- // object. The execution reaches here when Object.getOwnPropertyDescriptor
- // gets called on native object prototypes.
- return true;
- }
-
- MozjsGlobalEnvironment* global_environment =
- static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context));
- WrapperFactory* wrapper_factory = global_environment->wrapper_factory();
- if (!wrapper_factory->DoesObjectImplementInterface(
- object, base::GetTypeId<ArbitraryInterface>())) {
- MozjsExceptionState exception(context);
- exception.SetSimpleException(script::kDoesNotImplementInterface);
- return false;
- }
- MozjsExceptionState exception_state(context);
- JS::RootedValue result_value(context);
-
- WrapperPrivate* wrapper_private =
- WrapperPrivate::GetFromObject(context, object);
- ArbitraryInterface* impl =
- wrapper_private->wrappable<ArbitraryInterface>().get();
- TypeTraits<std::string >::ConversionType value;
- FromJSValue(context, vp, kNoConversionFlags, &exception_state,
- &value);
- if (exception_state.is_exception_set()) {
- return false;
- }
-
- impl->set_arbitrary_property(value);
- result_value.set(JS::UndefinedHandleValue);
- return !exception_state.is_exception_set();
-}
-
-JSBool fcn_arbitraryFunction(
- JSContext* context, uint32_t argc, JS::Value *vp) {
- JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
- // Compute the 'this' value.
- JS::RootedValue this_value(context, JS_ComputeThis(context, vp));
- // 'this' should be an object.
- JS::RootedObject object(context);
- if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) {
- return false;
- }
- if (!JS_ValueToObject(context, this_value, object.address())) {
- NOTREACHED();
- return false;
- }
- const JSClass* proto_class =
- MozjsArbitraryInterface::PrototypeClass(context);
- if (proto_class == JS_GetClass(object)) {
- // Simply returns true if the object is this class's prototype object.
- // There is no need to return any value due to the object is not a platform
- // object. The execution reaches here when Object.getOwnPropertyDescriptor
- // gets called on native object prototypes.
- return true;
- }
-
- MozjsGlobalEnvironment* global_environment =
- static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context));
- WrapperFactory* wrapper_factory = global_environment->wrapper_factory();
- if (!wrapper_factory->DoesObjectImplementInterface(
- object, base::GetTypeId<ArbitraryInterface>())) {
- MozjsExceptionState exception(context);
- exception.SetSimpleException(script::kDoesNotImplementInterface);
- return false;
- }
- MozjsExceptionState exception_state(context);
- JS::RootedValue result_value(context);
-
- WrapperPrivate* wrapper_private =
- WrapperPrivate::GetFromObject(context, object);
- ArbitraryInterface* impl =
- wrapper_private->wrappable<ArbitraryInterface>().get();
-
- impl->ArbitraryFunction();
- result_value.set(JS::UndefinedHandleValue);
- return !exception_state.is_exception_set();
-}
-
-
-const JSPropertySpec prototype_properties[] = {
- { // Read/Write property
- "arbitraryProperty", 0,
- JSPROP_SHARED | JSPROP_ENUMERATE,
- JSOP_WRAPPER(&get_arbitraryProperty),
- JSOP_WRAPPER(&set_arbitraryProperty),
- },
- JS_PS_END
-};
-
-const JSFunctionSpec prototype_functions[] = {
- {
- "arbitraryFunction",
- JSOP_WRAPPER(&fcn_arbitraryFunction),
- 0,
- JSPROP_ENUMERATE,
- NULL,
- },
- JS_FS_END
-};
-
-const JSPropertySpec interface_object_properties[] = {
- JS_PS_END
-};
-
-const JSFunctionSpec interface_object_functions[] = {
- JS_FS_END
-};
-
-const JSPropertySpec own_properties[] = {
- JS_PS_END
-};
-
-void InitializePrototypeAndInterfaceObject(
- InterfaceData* interface_data, JSContext* context,
- JS::HandleObject global_object) {
- DCHECK(!interface_data->prototype);
- DCHECK(!interface_data->interface_object);
- DCHECK(JS_IsGlobalObject(global_object));
-
- JS::RootedObject parent_prototype(
- context, JS_GetObjectPrototype(context, global_object));
- DCHECK(parent_prototype);
-
- // Create the Prototype object.
- interface_data->prototype = JS_NewObjectWithGivenProto(
- context, &interface_data->prototype_class_definition, parent_prototype,
- NULL);
- bool success = JS_DefineProperties(
- context, interface_data->prototype, prototype_properties);
- DCHECK(success);
- success = JS_DefineFunctions(
- context, interface_data->prototype, prototype_functions);
- DCHECK(success);
-
- JS::RootedObject function_prototype(
- context, JS_GetFunctionPrototype(context, global_object));
- DCHECK(function_prototype);
- // Create the Interface object.
- interface_data->interface_object = JS_NewObjectWithGivenProto(
- context, &interface_data->interface_object_class_definition,
- function_prototype, NULL);
-
- // Add the InterfaceObject.name property.
- JS::RootedObject rooted_interface_object(
- context, interface_data->interface_object);
- JS::RootedValue name_value(context);
- const char name[] =
- "ArbitraryInterface";
- name_value.setString(JS_NewStringCopyZ(context, name));
- success =
- JS_DefineProperty(context, rooted_interface_object, "name", name_value,
- JS_PropertyStub, JS_StrictPropertyStub,
- JSPROP_READONLY);
- DCHECK(success);
-
- // Add the InterfaceObject.length property. It is set to the length of the
- // shortest argument list of all overload constructors.
- JS::RootedValue length_value(context);
- length_value.setInt32(0);
- success =
- JS_DefineProperty(context, rooted_interface_object, "length",
- length_value, JS_PropertyStub, JS_StrictPropertyStub,
- JSPROP_READONLY);
- DCHECK(success);
-
- // Define interface object properties (including constants).
- success = JS_DefineProperties(context, rooted_interface_object,
- interface_object_properties);
- DCHECK(success);
- // Define interface object functions (static).
- success = JS_DefineFunctions(context, rooted_interface_object,
- interface_object_functions);
- DCHECK(success);
-
-
- // Set the Prototype.constructor and Constructor.prototype properties.
- DCHECK(interface_data->interface_object);
- DCHECK(interface_data->prototype);
- JS::RootedObject rooted_prototype(context, interface_data->prototype);
- success = JS_LinkConstructorAndPrototype(
- context,
- rooted_interface_object,
- rooted_prototype);
- DCHECK(success);
-}
-
-InterfaceData* GetInterfaceData(JSContext* context) {
- MozjsGlobalEnvironment* global_environment =
- static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context));
- // Use the address of the properties definition for this interface as a
- // unique key for looking up the InterfaceData for this interface.
- intptr_t key = reinterpret_cast<intptr_t>(&own_properties);
- InterfaceData* interface_data = global_environment->GetInterfaceData(key);
- if (!interface_data) {
- interface_data = CreateCachedInterfaceData();
- DCHECK(interface_data);
- global_environment->CacheInterfaceData(key, interface_data);
- DCHECK_EQ(interface_data, global_environment->GetInterfaceData(key));
- }
- return interface_data;
-}
-
-} // namespace
-
-// static
-JSObject* MozjsArbitraryInterface::CreateProxy(
- JSContext* context, const scoped_refptr<Wrappable>& wrappable) {
- DCHECK(MozjsGlobalEnvironment::GetFromContext(context));
- JS::RootedObject global_object(
- context,
- MozjsGlobalEnvironment::GetFromContext(context)->global_object());
- DCHECK(global_object);
-
- InterfaceData* interface_data = GetInterfaceData(context);
- JS::RootedObject prototype(context, GetPrototype(context, global_object));
- DCHECK(prototype);
- JS::RootedObject new_object(context, JS_NewObjectWithGivenProto(
- context, &interface_data->instance_class_definition, prototype, NULL));
- DCHECK(new_object);
- JS::RootedObject proxy(context,
- ProxyHandler::NewProxy(context, new_object, prototype, NULL,
- proxy_handler.Pointer()));
- WrapperPrivate::AddPrivateData(context, proxy, wrappable);
- return proxy;
-}
-
-//static
-const JSClass* MozjsArbitraryInterface::PrototypeClass(
- JSContext* context) {
- DCHECK(MozjsGlobalEnvironment::GetFromContext(context));
- JS::RootedObject global_object(
- context,
- MozjsGlobalEnvironment::GetFromContext(context)->global_object());
- DCHECK(global_object);
-
- JS::RootedObject prototype(context, GetPrototype(context, global_object));
- JSClass* proto_class = JS_GetClass(*prototype.address());
- return proto_class;
-}
-
-// static
-JSObject* MozjsArbitraryInterface::GetPrototype(
- JSContext* context, JS::HandleObject global_object) {
- DCHECK(JS_IsGlobalObject(global_object));
-
- InterfaceData* interface_data = GetInterfaceData(context);
- if (!interface_data->prototype) {
- // Create new prototype that has all the props and methods
- InitializePrototypeAndInterfaceObject(
- interface_data, context, global_object);
- }
- DCHECK(interface_data->prototype);
- return interface_data->prototype;
-}
-
-// static
-JSObject* MozjsArbitraryInterface::GetInterfaceObject(
- JSContext* context, JS::HandleObject global_object) {
- DCHECK(JS_IsGlobalObject(global_object));
-
- InterfaceData* interface_data = GetInterfaceData(context);
- if (!interface_data->interface_object) {
- InitializePrototypeAndInterfaceObject(
- interface_data, context, global_object);
- }
- DCHECK(interface_data->interface_object);
- return interface_data->interface_object;
-}
-
-
-namespace {
-JSBool Constructor(JSContext* context, unsigned int argc, JS::Value* vp) {
- MozjsExceptionState exception_state(context);
- JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
-
- scoped_refptr<ArbitraryInterface> new_object =
- new ArbitraryInterface();
- JS::RootedValue result_value(context);
- ToJSValue(context, new_object, &result_value);
- DCHECK(result_value.isObject());
- JS::RootedObject result_object(context, JSVAL_TO_OBJECT(result_value));
- args.rval().setObject(*result_object);
- return true;
-}
-} // namespace
-
-
-} // namespace testing
-} // namespace bindings
-} // namespace cobalt
diff --git a/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_arbitrary_interface.h b/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_arbitrary_interface.h
deleted file mode 100644
index e88e87b..0000000
--- a/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_arbitrary_interface.h
+++ /dev/null
@@ -1,52 +0,0 @@
-// Copyright 2017 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/mozjs/templates/interface.h.template
-
-#ifndef MozjsArbitraryInterface_h
-#define MozjsArbitraryInterface_h
-
-#include "base/hash_tables.h"
-#include "base/lazy_instance.h"
-#include "base/memory/ref_counted.h"
-#include "base/threading/thread_checker.h"
-#include "cobalt/base/polymorphic_downcast.h"
-#include "cobalt/script/wrappable.h"
-#include "cobalt/bindings/testing/arbitrary_interface.h"
-
-#include "third_party/mozjs/js/src/jsapi.h"
-
-namespace cobalt {
-namespace bindings {
-namespace testing {
-
-class MozjsArbitraryInterface {
- public:
- static JSObject* CreateProxy(JSContext* context,
- const scoped_refptr<script::Wrappable>& wrappable);
- static const JSClass* PrototypeClass(JSContext* context);
- static JSObject* GetPrototype(JSContext* context,
- JS::HandleObject global_object);
- static JSObject* GetInterfaceObject(JSContext* context,
- JS::HandleObject global_object);
-};
-
-} // namespace testing
-} // namespace bindings
-} // namespace cobalt
-
-#endif // MozjsArbitraryInterface_h
diff --git a/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_base_interface.cc b/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_base_interface.cc
deleted file mode 100644
index a810666..0000000
--- a/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_base_interface.cc
+++ /dev/null
@@ -1,494 +0,0 @@
-// Copyright 2017 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/mozjs/templates/interface.cc.template
-
-#include "cobalt/bindings/testing/mozjs_base_interface.h"
-
-#include "base/debug/trace_event.h"
-#include "cobalt/base/polymorphic_downcast.h"
-#include "cobalt/script/global_environment.h"
-#include "cobalt/script/opaque_handle.h"
-#include "cobalt/script/script_value.h"
-
-#include "mozjs_gen_type_conversion.h"
-
-#include "base/lazy_instance.h"
-#include "cobalt/script/exception_state.h"
-#include "cobalt/script/mozjs/callback_function_conversion.h"
-#include "cobalt/script/mozjs/conversion_helpers.h"
-#include "cobalt/script/mozjs/mozjs_callback_function.h"
-#include "cobalt/script/mozjs/mozjs_exception_state.h"
-#include "cobalt/script/mozjs/mozjs_global_environment.h"
-#include "cobalt/script/mozjs/mozjs_object_handle.h"
-#include "cobalt/script/mozjs/mozjs_property_enumerator.h"
-#include "cobalt/script/mozjs/mozjs_user_object_holder.h"
-#include "cobalt/script/mozjs/mozjs_value_handle.h"
-#include "cobalt/script/mozjs/native_promise.h"
-#include "cobalt/script/mozjs/proxy_handler.h"
-#include "cobalt/script/mozjs/type_traits.h"
-#include "cobalt/script/mozjs/wrapper_factory.h"
-#include "cobalt/script/mozjs/wrapper_private.h"
-#include "cobalt/script/property_enumerator.h"
-#include "cobalt/script/sequence.h"
-#include "third_party/mozjs/js/src/jsapi.h"
-#include "third_party/mozjs/js/src/jsfriendapi.h"
-
-namespace {
-using cobalt::bindings::testing::BaseInterface;
-using cobalt::bindings::testing::MozjsBaseInterface;
-using cobalt::script::CallbackInterfaceTraits;
-using cobalt::script::GlobalEnvironment;
-using cobalt::script::OpaqueHandle;
-using cobalt::script::OpaqueHandleHolder;
-using cobalt::script::ScriptValue;
-using cobalt::script::ValueHandle;
-using cobalt::script::Wrappable;
-
-using cobalt::script::CallbackFunction;
-using cobalt::script::CallbackInterfaceTraits;
-using cobalt::script::ExceptionState;
-using cobalt::script::Wrappable;
-using cobalt::script::mozjs::FromJSValue;
-using cobalt::script::mozjs::InterfaceData;
-using cobalt::script::mozjs::MozjsCallbackFunction;
-using cobalt::script::mozjs::MozjsExceptionState;
-using cobalt::script::mozjs::MozjsGlobalEnvironment;
-using cobalt::script::mozjs::MozjsPropertyEnumerator;
-using cobalt::script::mozjs::MozjsUserObjectHolder;
-using cobalt::script::mozjs::ProxyHandler;
-using cobalt::script::mozjs::ToJSValue;
-using cobalt::script::mozjs::TypeTraits;
-using cobalt::script::mozjs::WrapperFactory;
-using cobalt::script::mozjs::WrapperPrivate;
-using cobalt::script::mozjs::kConversionFlagClamped;
-using cobalt::script::mozjs::kConversionFlagNullable;
-using cobalt::script::mozjs::kConversionFlagRestricted;
-using cobalt::script::mozjs::kConversionFlagTreatNullAsEmptyString;
-using cobalt::script::mozjs::kConversionFlagTreatUndefinedAsEmptyString;
-using cobalt::script::mozjs::kNoConversionFlags;
-} // namespace
-
-namespace cobalt {
-namespace bindings {
-namespace testing {
-
-namespace {
-
-class MozjsBaseInterfaceHandler : public ProxyHandler {
- public:
- MozjsBaseInterfaceHandler()
- : ProxyHandler(indexed_property_hooks, named_property_hooks) {}
-
- private:
- static NamedPropertyHooks named_property_hooks;
- static IndexedPropertyHooks indexed_property_hooks;
-};
-
-ProxyHandler::NamedPropertyHooks
-MozjsBaseInterfaceHandler::named_property_hooks = {
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
-};
-ProxyHandler::IndexedPropertyHooks
-MozjsBaseInterfaceHandler::indexed_property_hooks = {
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
-};
-
-static base::LazyInstance<MozjsBaseInterfaceHandler>
- proxy_handler;
-
-JSBool Constructor(JSContext* context, unsigned int argc, JS::Value* vp);
-JSBool HasInstance(JSContext *context, JS::HandleObject type,
- JS::MutableHandleValue vp, JSBool *success) {
- JS::RootedObject global_object(
- context, JS_GetGlobalForObject(context, type));
- DCHECK(global_object);
-
- JS::RootedObject prototype(
- context, MozjsBaseInterface::GetPrototype(context, global_object));
-
- // |IsDelegate| walks the prototype chain of an object returning true if
- // .prototype is found.
- bool is_delegate;
- if (!IsDelegate(context, prototype, vp, &is_delegate)) {
- *success = false;
- return false;
- }
-
- *success = is_delegate;
- return true;
-}
-
-InterfaceData* CreateCachedInterfaceData() {
- InterfaceData* interface_data = new InterfaceData();
- memset(&interface_data->instance_class_definition, 0,
- sizeof(interface_data->instance_class_definition));
- memset(&interface_data->prototype_class_definition, 0,
- sizeof(interface_data->prototype_class_definition));
- memset(&interface_data->interface_object_class_definition, 0,
- sizeof(interface_data->interface_object_class_definition));
-
- JSClass* instance_class = &interface_data->instance_class_definition;
- const int kGlobalFlags = 0;
- instance_class->name = "BaseInterface";
- instance_class->flags = kGlobalFlags | JSCLASS_HAS_PRIVATE;
- instance_class->addProperty = JS_PropertyStub;
- instance_class->delProperty = JS_DeletePropertyStub;
- instance_class->getProperty = JS_PropertyStub;
- instance_class->setProperty = JS_StrictPropertyStub;
- instance_class->enumerate = JS_EnumerateStub;
- instance_class->resolve = JS_ResolveStub;
- instance_class->convert = JS_ConvertStub;
- // Function to be called before on object of this class is garbage collected.
- instance_class->finalize = &WrapperPrivate::Finalizer;
- // Called to trace objects that can be referenced from this object.
- instance_class->trace = &WrapperPrivate::Trace;
-
- JSClass* prototype_class = &interface_data->prototype_class_definition;
- prototype_class->name = "BaseInterfacePrototype";
- prototype_class->flags = 0;
- prototype_class->addProperty = JS_PropertyStub;
- prototype_class->delProperty = JS_DeletePropertyStub;
- prototype_class->getProperty = JS_PropertyStub;
- prototype_class->setProperty = JS_StrictPropertyStub;
- prototype_class->enumerate = JS_EnumerateStub;
- prototype_class->resolve = JS_ResolveStub;
- prototype_class->convert = JS_ConvertStub;
-
- JSClass* interface_object_class =
- &interface_data->interface_object_class_definition;
- interface_object_class->name = "BaseInterfaceConstructor";
- interface_object_class->flags = 0;
- interface_object_class->addProperty = JS_PropertyStub;
- interface_object_class->delProperty = JS_DeletePropertyStub;
- interface_object_class->getProperty = JS_PropertyStub;
- interface_object_class->setProperty = JS_StrictPropertyStub;
- interface_object_class->enumerate = JS_EnumerateStub;
- interface_object_class->resolve = JS_ResolveStub;
- interface_object_class->convert = JS_ConvertStub;
- interface_object_class->hasInstance = &HasInstance;
- interface_object_class->construct = Constructor;
- return interface_data;
-}
-
-JSBool get_baseAttribute(
- JSContext* context, JS::HandleObject object, JS::HandleId id,
- JS::MutableHandleValue vp) {
- const JSClass* proto_class =
- MozjsBaseInterface::PrototypeClass(context);
- if (proto_class == JS_GetClass(object)) {
- // Simply returns true if the object is this class's prototype object.
- // There is no need to return any value due to the object is not a platform
- // object. The execution reaches here when Object.getOwnPropertyDescriptor
- // gets called on native object prototypes.
- return true;
- }
-
- MozjsGlobalEnvironment* global_environment =
- static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context));
- WrapperFactory* wrapper_factory = global_environment->wrapper_factory();
- if (!wrapper_factory->DoesObjectImplementInterface(
- object, base::GetTypeId<BaseInterface>())) {
- MozjsExceptionState exception(context);
- exception.SetSimpleException(script::kDoesNotImplementInterface);
- return false;
- }
- MozjsExceptionState exception_state(context);
- JS::RootedValue result_value(context);
-
- WrapperPrivate* wrapper_private =
- WrapperPrivate::GetFromObject(context, object);
- BaseInterface* impl =
- wrapper_private->wrappable<BaseInterface>().get();
-
- if (!exception_state.is_exception_set()) {
- ToJSValue(context,
- impl->base_attribute(),
- &result_value);
- }
- if (!exception_state.is_exception_set()) {
- vp.set(result_value);
- }
- return !exception_state.is_exception_set();
-}
-
-JSBool fcn_baseOperation(
- JSContext* context, uint32_t argc, JS::Value *vp) {
- JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
- // Compute the 'this' value.
- JS::RootedValue this_value(context, JS_ComputeThis(context, vp));
- // 'this' should be an object.
- JS::RootedObject object(context);
- if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) {
- return false;
- }
- if (!JS_ValueToObject(context, this_value, object.address())) {
- NOTREACHED();
- return false;
- }
- const JSClass* proto_class =
- MozjsBaseInterface::PrototypeClass(context);
- if (proto_class == JS_GetClass(object)) {
- // Simply returns true if the object is this class's prototype object.
- // There is no need to return any value due to the object is not a platform
- // object. The execution reaches here when Object.getOwnPropertyDescriptor
- // gets called on native object prototypes.
- return true;
- }
-
- MozjsGlobalEnvironment* global_environment =
- static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context));
- WrapperFactory* wrapper_factory = global_environment->wrapper_factory();
- if (!wrapper_factory->DoesObjectImplementInterface(
- object, base::GetTypeId<BaseInterface>())) {
- MozjsExceptionState exception(context);
- exception.SetSimpleException(script::kDoesNotImplementInterface);
- return false;
- }
- MozjsExceptionState exception_state(context);
- JS::RootedValue result_value(context);
-
- WrapperPrivate* wrapper_private =
- WrapperPrivate::GetFromObject(context, object);
- BaseInterface* impl =
- wrapper_private->wrappable<BaseInterface>().get();
-
- impl->BaseOperation();
- result_value.set(JS::UndefinedHandleValue);
- return !exception_state.is_exception_set();
-}
-
-
-const JSPropertySpec prototype_properties[] = {
- { // Readonly attribute
- "baseAttribute", 0,
- JSPROP_SHARED | JSPROP_ENUMERATE | JSPROP_READONLY,
- JSOP_WRAPPER(&get_baseAttribute),
- JSOP_NULLWRAPPER,
- },
- JS_PS_END
-};
-
-const JSFunctionSpec prototype_functions[] = {
- {
- "baseOperation",
- JSOP_WRAPPER(&fcn_baseOperation),
- 0,
- JSPROP_ENUMERATE,
- NULL,
- },
- JS_FS_END
-};
-
-const JSPropertySpec interface_object_properties[] = {
- JS_PS_END
-};
-
-const JSFunctionSpec interface_object_functions[] = {
- JS_FS_END
-};
-
-const JSPropertySpec own_properties[] = {
- JS_PS_END
-};
-
-void InitializePrototypeAndInterfaceObject(
- InterfaceData* interface_data, JSContext* context,
- JS::HandleObject global_object) {
- DCHECK(!interface_data->prototype);
- DCHECK(!interface_data->interface_object);
- DCHECK(JS_IsGlobalObject(global_object));
-
- JS::RootedObject parent_prototype(
- context, JS_GetObjectPrototype(context, global_object));
- DCHECK(parent_prototype);
-
- // Create the Prototype object.
- interface_data->prototype = JS_NewObjectWithGivenProto(
- context, &interface_data->prototype_class_definition, parent_prototype,
- NULL);
- bool success = JS_DefineProperties(
- context, interface_data->prototype, prototype_properties);
- DCHECK(success);
- success = JS_DefineFunctions(
- context, interface_data->prototype, prototype_functions);
- DCHECK(success);
-
- JS::RootedObject function_prototype(
- context, JS_GetFunctionPrototype(context, global_object));
- DCHECK(function_prototype);
- // Create the Interface object.
- interface_data->interface_object = JS_NewObjectWithGivenProto(
- context, &interface_data->interface_object_class_definition,
- function_prototype, NULL);
-
- // Add the InterfaceObject.name property.
- JS::RootedObject rooted_interface_object(
- context, interface_data->interface_object);
- JS::RootedValue name_value(context);
- const char name[] =
- "BaseInterface";
- name_value.setString(JS_NewStringCopyZ(context, name));
- success =
- JS_DefineProperty(context, rooted_interface_object, "name", name_value,
- JS_PropertyStub, JS_StrictPropertyStub,
- JSPROP_READONLY);
- DCHECK(success);
-
- // Add the InterfaceObject.length property. It is set to the length of the
- // shortest argument list of all overload constructors.
- JS::RootedValue length_value(context);
- length_value.setInt32(0);
- success =
- JS_DefineProperty(context, rooted_interface_object, "length",
- length_value, JS_PropertyStub, JS_StrictPropertyStub,
- JSPROP_READONLY);
- DCHECK(success);
-
- // Define interface object properties (including constants).
- success = JS_DefineProperties(context, rooted_interface_object,
- interface_object_properties);
- DCHECK(success);
- // Define interface object functions (static).
- success = JS_DefineFunctions(context, rooted_interface_object,
- interface_object_functions);
- DCHECK(success);
-
-
- // Set the Prototype.constructor and Constructor.prototype properties.
- DCHECK(interface_data->interface_object);
- DCHECK(interface_data->prototype);
- JS::RootedObject rooted_prototype(context, interface_data->prototype);
- success = JS_LinkConstructorAndPrototype(
- context,
- rooted_interface_object,
- rooted_prototype);
- DCHECK(success);
-}
-
-InterfaceData* GetInterfaceData(JSContext* context) {
- MozjsGlobalEnvironment* global_environment =
- static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context));
- // Use the address of the properties definition for this interface as a
- // unique key for looking up the InterfaceData for this interface.
- intptr_t key = reinterpret_cast<intptr_t>(&own_properties);
- InterfaceData* interface_data = global_environment->GetInterfaceData(key);
- if (!interface_data) {
- interface_data = CreateCachedInterfaceData();
- DCHECK(interface_data);
- global_environment->CacheInterfaceData(key, interface_data);
- DCHECK_EQ(interface_data, global_environment->GetInterfaceData(key));
- }
- return interface_data;
-}
-
-} // namespace
-
-// static
-JSObject* MozjsBaseInterface::CreateProxy(
- JSContext* context, const scoped_refptr<Wrappable>& wrappable) {
- DCHECK(MozjsGlobalEnvironment::GetFromContext(context));
- JS::RootedObject global_object(
- context,
- MozjsGlobalEnvironment::GetFromContext(context)->global_object());
- DCHECK(global_object);
-
- InterfaceData* interface_data = GetInterfaceData(context);
- JS::RootedObject prototype(context, GetPrototype(context, global_object));
- DCHECK(prototype);
- JS::RootedObject new_object(context, JS_NewObjectWithGivenProto(
- context, &interface_data->instance_class_definition, prototype, NULL));
- DCHECK(new_object);
- JS::RootedObject proxy(context,
- ProxyHandler::NewProxy(context, new_object, prototype, NULL,
- proxy_handler.Pointer()));
- WrapperPrivate::AddPrivateData(context, proxy, wrappable);
- return proxy;
-}
-
-//static
-const JSClass* MozjsBaseInterface::PrototypeClass(
- JSContext* context) {
- DCHECK(MozjsGlobalEnvironment::GetFromContext(context));
- JS::RootedObject global_object(
- context,
- MozjsGlobalEnvironment::GetFromContext(context)->global_object());
- DCHECK(global_object);
-
- JS::RootedObject prototype(context, GetPrototype(context, global_object));
- JSClass* proto_class = JS_GetClass(*prototype.address());
- return proto_class;
-}
-
-// static
-JSObject* MozjsBaseInterface::GetPrototype(
- JSContext* context, JS::HandleObject global_object) {
- DCHECK(JS_IsGlobalObject(global_object));
-
- InterfaceData* interface_data = GetInterfaceData(context);
- if (!interface_data->prototype) {
- // Create new prototype that has all the props and methods
- InitializePrototypeAndInterfaceObject(
- interface_data, context, global_object);
- }
- DCHECK(interface_data->prototype);
- return interface_data->prototype;
-}
-
-// static
-JSObject* MozjsBaseInterface::GetInterfaceObject(
- JSContext* context, JS::HandleObject global_object) {
- DCHECK(JS_IsGlobalObject(global_object));
-
- InterfaceData* interface_data = GetInterfaceData(context);
- if (!interface_data->interface_object) {
- InitializePrototypeAndInterfaceObject(
- interface_data, context, global_object);
- }
- DCHECK(interface_data->interface_object);
- return interface_data->interface_object;
-}
-
-
-namespace {
-JSBool Constructor(JSContext* context, unsigned int argc, JS::Value* vp) {
- MozjsExceptionState exception_state(context);
- JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
-
- scoped_refptr<BaseInterface> new_object =
- new BaseInterface();
- JS::RootedValue result_value(context);
- ToJSValue(context, new_object, &result_value);
- DCHECK(result_value.isObject());
- JS::RootedObject result_object(context, JSVAL_TO_OBJECT(result_value));
- args.rval().setObject(*result_object);
- return true;
-}
-} // namespace
-
-
-} // namespace testing
-} // namespace bindings
-} // namespace cobalt
diff --git a/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_base_interface.h b/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_base_interface.h
deleted file mode 100644
index 735658e..0000000
--- a/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_base_interface.h
+++ /dev/null
@@ -1,52 +0,0 @@
-// Copyright 2017 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/mozjs/templates/interface.h.template
-
-#ifndef MozjsBaseInterface_h
-#define MozjsBaseInterface_h
-
-#include "base/hash_tables.h"
-#include "base/lazy_instance.h"
-#include "base/memory/ref_counted.h"
-#include "base/threading/thread_checker.h"
-#include "cobalt/base/polymorphic_downcast.h"
-#include "cobalt/script/wrappable.h"
-#include "cobalt/bindings/testing/base_interface.h"
-
-#include "third_party/mozjs/js/src/jsapi.h"
-
-namespace cobalt {
-namespace bindings {
-namespace testing {
-
-class MozjsBaseInterface {
- public:
- static JSObject* CreateProxy(JSContext* context,
- const scoped_refptr<script::Wrappable>& wrappable);
- static const JSClass* PrototypeClass(JSContext* context);
- static JSObject* GetPrototype(JSContext* context,
- JS::HandleObject global_object);
- static JSObject* GetInterfaceObject(JSContext* context,
- JS::HandleObject global_object);
-};
-
-} // namespace testing
-} // namespace bindings
-} // namespace cobalt
-
-#endif // MozjsBaseInterface_h
diff --git a/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_boolean_type_test_interface.cc b/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_boolean_type_test_interface.cc
deleted file mode 100644
index a972552..0000000
--- a/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_boolean_type_test_interface.cc
+++ /dev/null
@@ -1,587 +0,0 @@
-// Copyright 2017 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/mozjs/templates/interface.cc.template
-
-#include "cobalt/bindings/testing/mozjs_boolean_type_test_interface.h"
-
-#include "base/debug/trace_event.h"
-#include "cobalt/base/polymorphic_downcast.h"
-#include "cobalt/script/global_environment.h"
-#include "cobalt/script/opaque_handle.h"
-#include "cobalt/script/script_value.h"
-
-#include "mozjs_gen_type_conversion.h"
-
-#include "base/lazy_instance.h"
-#include "cobalt/script/exception_state.h"
-#include "cobalt/script/mozjs/callback_function_conversion.h"
-#include "cobalt/script/mozjs/conversion_helpers.h"
-#include "cobalt/script/mozjs/mozjs_callback_function.h"
-#include "cobalt/script/mozjs/mozjs_exception_state.h"
-#include "cobalt/script/mozjs/mozjs_global_environment.h"
-#include "cobalt/script/mozjs/mozjs_object_handle.h"
-#include "cobalt/script/mozjs/mozjs_property_enumerator.h"
-#include "cobalt/script/mozjs/mozjs_user_object_holder.h"
-#include "cobalt/script/mozjs/mozjs_value_handle.h"
-#include "cobalt/script/mozjs/native_promise.h"
-#include "cobalt/script/mozjs/proxy_handler.h"
-#include "cobalt/script/mozjs/type_traits.h"
-#include "cobalt/script/mozjs/wrapper_factory.h"
-#include "cobalt/script/mozjs/wrapper_private.h"
-#include "cobalt/script/property_enumerator.h"
-#include "cobalt/script/sequence.h"
-#include "third_party/mozjs/js/src/jsapi.h"
-#include "third_party/mozjs/js/src/jsfriendapi.h"
-
-namespace {
-using cobalt::bindings::testing::BooleanTypeTestInterface;
-using cobalt::bindings::testing::MozjsBooleanTypeTestInterface;
-using cobalt::script::CallbackInterfaceTraits;
-using cobalt::script::GlobalEnvironment;
-using cobalt::script::OpaqueHandle;
-using cobalt::script::OpaqueHandleHolder;
-using cobalt::script::ScriptValue;
-using cobalt::script::ValueHandle;
-using cobalt::script::Wrappable;
-
-using cobalt::script::CallbackFunction;
-using cobalt::script::CallbackInterfaceTraits;
-using cobalt::script::ExceptionState;
-using cobalt::script::Wrappable;
-using cobalt::script::mozjs::FromJSValue;
-using cobalt::script::mozjs::InterfaceData;
-using cobalt::script::mozjs::MozjsCallbackFunction;
-using cobalt::script::mozjs::MozjsExceptionState;
-using cobalt::script::mozjs::MozjsGlobalEnvironment;
-using cobalt::script::mozjs::MozjsPropertyEnumerator;
-using cobalt::script::mozjs::MozjsUserObjectHolder;
-using cobalt::script::mozjs::ProxyHandler;
-using cobalt::script::mozjs::ToJSValue;
-using cobalt::script::mozjs::TypeTraits;
-using cobalt::script::mozjs::WrapperFactory;
-using cobalt::script::mozjs::WrapperPrivate;
-using cobalt::script::mozjs::kConversionFlagClamped;
-using cobalt::script::mozjs::kConversionFlagNullable;
-using cobalt::script::mozjs::kConversionFlagRestricted;
-using cobalt::script::mozjs::kConversionFlagTreatNullAsEmptyString;
-using cobalt::script::mozjs::kConversionFlagTreatUndefinedAsEmptyString;
-using cobalt::script::mozjs::kNoConversionFlags;
-} // namespace
-
-namespace cobalt {
-namespace bindings {
-namespace testing {
-
-namespace {
-
-class MozjsBooleanTypeTestInterfaceHandler : public ProxyHandler {
- public:
- MozjsBooleanTypeTestInterfaceHandler()
- : ProxyHandler(indexed_property_hooks, named_property_hooks) {}
-
- private:
- static NamedPropertyHooks named_property_hooks;
- static IndexedPropertyHooks indexed_property_hooks;
-};
-
-ProxyHandler::NamedPropertyHooks
-MozjsBooleanTypeTestInterfaceHandler::named_property_hooks = {
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
-};
-ProxyHandler::IndexedPropertyHooks
-MozjsBooleanTypeTestInterfaceHandler::indexed_property_hooks = {
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
-};
-
-static base::LazyInstance<MozjsBooleanTypeTestInterfaceHandler>
- proxy_handler;
-
-JSBool HasInstance(JSContext *context, JS::HandleObject type,
- JS::MutableHandleValue vp, JSBool *success) {
- JS::RootedObject global_object(
- context, JS_GetGlobalForObject(context, type));
- DCHECK(global_object);
-
- JS::RootedObject prototype(
- context, MozjsBooleanTypeTestInterface::GetPrototype(context, global_object));
-
- // |IsDelegate| walks the prototype chain of an object returning true if
- // .prototype is found.
- bool is_delegate;
- if (!IsDelegate(context, prototype, vp, &is_delegate)) {
- *success = false;
- return false;
- }
-
- *success = is_delegate;
- return true;
-}
-
-InterfaceData* CreateCachedInterfaceData() {
- InterfaceData* interface_data = new InterfaceData();
- memset(&interface_data->instance_class_definition, 0,
- sizeof(interface_data->instance_class_definition));
- memset(&interface_data->prototype_class_definition, 0,
- sizeof(interface_data->prototype_class_definition));
- memset(&interface_data->interface_object_class_definition, 0,
- sizeof(interface_data->interface_object_class_definition));
-
- JSClass* instance_class = &interface_data->instance_class_definition;
- const int kGlobalFlags = 0;
- instance_class->name = "BooleanTypeTestInterface";
- instance_class->flags = kGlobalFlags | JSCLASS_HAS_PRIVATE;
- instance_class->addProperty = JS_PropertyStub;
- instance_class->delProperty = JS_DeletePropertyStub;
- instance_class->getProperty = JS_PropertyStub;
- instance_class->setProperty = JS_StrictPropertyStub;
- instance_class->enumerate = JS_EnumerateStub;
- instance_class->resolve = JS_ResolveStub;
- instance_class->convert = JS_ConvertStub;
- // Function to be called before on object of this class is garbage collected.
- instance_class->finalize = &WrapperPrivate::Finalizer;
- // Called to trace objects that can be referenced from this object.
- instance_class->trace = &WrapperPrivate::Trace;
-
- JSClass* prototype_class = &interface_data->prototype_class_definition;
- prototype_class->name = "BooleanTypeTestInterfacePrototype";
- prototype_class->flags = 0;
- prototype_class->addProperty = JS_PropertyStub;
- prototype_class->delProperty = JS_DeletePropertyStub;
- prototype_class->getProperty = JS_PropertyStub;
- prototype_class->setProperty = JS_StrictPropertyStub;
- prototype_class->enumerate = JS_EnumerateStub;
- prototype_class->resolve = JS_ResolveStub;
- prototype_class->convert = JS_ConvertStub;
-
- JSClass* interface_object_class =
- &interface_data->interface_object_class_definition;
- interface_object_class->name = "BooleanTypeTestInterfaceConstructor";
- interface_object_class->flags = 0;
- interface_object_class->addProperty = JS_PropertyStub;
- interface_object_class->delProperty = JS_DeletePropertyStub;
- interface_object_class->getProperty = JS_PropertyStub;
- interface_object_class->setProperty = JS_StrictPropertyStub;
- interface_object_class->enumerate = JS_EnumerateStub;
- interface_object_class->resolve = JS_ResolveStub;
- interface_object_class->convert = JS_ConvertStub;
- interface_object_class->hasInstance = &HasInstance;
- return interface_data;
-}
-
-JSBool get_booleanProperty(
- JSContext* context, JS::HandleObject object, JS::HandleId id,
- JS::MutableHandleValue vp) {
- const JSClass* proto_class =
- MozjsBooleanTypeTestInterface::PrototypeClass(context);
- if (proto_class == JS_GetClass(object)) {
- // Simply returns true if the object is this class's prototype object.
- // There is no need to return any value due to the object is not a platform
- // object. The execution reaches here when Object.getOwnPropertyDescriptor
- // gets called on native object prototypes.
- return true;
- }
-
- MozjsGlobalEnvironment* global_environment =
- static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context));
- WrapperFactory* wrapper_factory = global_environment->wrapper_factory();
- if (!wrapper_factory->DoesObjectImplementInterface(
- object, base::GetTypeId<BooleanTypeTestInterface>())) {
- MozjsExceptionState exception(context);
- exception.SetSimpleException(script::kDoesNotImplementInterface);
- return false;
- }
- MozjsExceptionState exception_state(context);
- JS::RootedValue result_value(context);
-
- WrapperPrivate* wrapper_private =
- WrapperPrivate::GetFromObject(context, object);
- BooleanTypeTestInterface* impl =
- wrapper_private->wrappable<BooleanTypeTestInterface>().get();
-
- if (!exception_state.is_exception_set()) {
- ToJSValue(context,
- impl->boolean_property(),
- &result_value);
- }
- if (!exception_state.is_exception_set()) {
- vp.set(result_value);
- }
- return !exception_state.is_exception_set();
-}
-
-JSBool set_booleanProperty(
- JSContext* context, JS::HandleObject object, JS::HandleId id,
- JSBool strict, JS::MutableHandleValue vp) {
- const JSClass* proto_class =
- MozjsBooleanTypeTestInterface::PrototypeClass(context);
- if (proto_class == JS_GetClass(object)) {
- // Simply returns true if the object is this class's prototype object.
- // There is no need to return any value due to the object is not a platform
- // object. The execution reaches here when Object.getOwnPropertyDescriptor
- // gets called on native object prototypes.
- return true;
- }
-
- MozjsGlobalEnvironment* global_environment =
- static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context));
- WrapperFactory* wrapper_factory = global_environment->wrapper_factory();
- if (!wrapper_factory->DoesObjectImplementInterface(
- object, base::GetTypeId<BooleanTypeTestInterface>())) {
- MozjsExceptionState exception(context);
- exception.SetSimpleException(script::kDoesNotImplementInterface);
- return false;
- }
- MozjsExceptionState exception_state(context);
- JS::RootedValue result_value(context);
-
- WrapperPrivate* wrapper_private =
- WrapperPrivate::GetFromObject(context, object);
- BooleanTypeTestInterface* impl =
- wrapper_private->wrappable<BooleanTypeTestInterface>().get();
- TypeTraits<bool >::ConversionType value;
- FromJSValue(context, vp, kNoConversionFlags, &exception_state,
- &value);
- if (exception_state.is_exception_set()) {
- return false;
- }
-
- impl->set_boolean_property(value);
- result_value.set(JS::UndefinedHandleValue);
- return !exception_state.is_exception_set();
-}
-
-JSBool fcn_booleanArgumentOperation(
- JSContext* context, uint32_t argc, JS::Value *vp) {
- JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
- // Compute the 'this' value.
- JS::RootedValue this_value(context, JS_ComputeThis(context, vp));
- // 'this' should be an object.
- JS::RootedObject object(context);
- if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) {
- return false;
- }
- if (!JS_ValueToObject(context, this_value, object.address())) {
- NOTREACHED();
- return false;
- }
- const JSClass* proto_class =
- MozjsBooleanTypeTestInterface::PrototypeClass(context);
- if (proto_class == JS_GetClass(object)) {
- // Simply returns true if the object is this class's prototype object.
- // There is no need to return any value due to the object is not a platform
- // object. The execution reaches here when Object.getOwnPropertyDescriptor
- // gets called on native object prototypes.
- return true;
- }
-
- MozjsGlobalEnvironment* global_environment =
- static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context));
- WrapperFactory* wrapper_factory = global_environment->wrapper_factory();
- if (!wrapper_factory->DoesObjectImplementInterface(
- object, base::GetTypeId<BooleanTypeTestInterface>())) {
- MozjsExceptionState exception(context);
- exception.SetSimpleException(script::kDoesNotImplementInterface);
- return false;
- }
- MozjsExceptionState exception_state(context);
- JS::RootedValue result_value(context);
-
- WrapperPrivate* wrapper_private =
- WrapperPrivate::GetFromObject(context, object);
- BooleanTypeTestInterface* impl =
- wrapper_private->wrappable<BooleanTypeTestInterface>().get();
- const size_t kMinArguments = 1;
- if (args.length() < kMinArguments) {
- exception_state.SetSimpleException(script::kInvalidNumberOfArguments);
- return false;
- }
- // Non-optional arguments
- TypeTraits<bool >::ConversionType arg1;
-
- DCHECK_LT(0, args.length());
- JS::RootedValue non_optional_value0(
- context, args[0]);
- FromJSValue(context,
- non_optional_value0,
- kNoConversionFlags,
- &exception_state, &arg1);
- if (exception_state.is_exception_set()) {
- return false;
- }
-
- impl->BooleanArgumentOperation(arg1);
- result_value.set(JS::UndefinedHandleValue);
- return !exception_state.is_exception_set();
-}
-
-JSBool fcn_booleanReturnOperation(
- JSContext* context, uint32_t argc, JS::Value *vp) {
- JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
- // Compute the 'this' value.
- JS::RootedValue this_value(context, JS_ComputeThis(context, vp));
- // 'this' should be an object.
- JS::RootedObject object(context);
- if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) {
- return false;
- }
- if (!JS_ValueToObject(context, this_value, object.address())) {
- NOTREACHED();
- return false;
- }
- const JSClass* proto_class =
- MozjsBooleanTypeTestInterface::PrototypeClass(context);
- if (proto_class == JS_GetClass(object)) {
- // Simply returns true if the object is this class's prototype object.
- // There is no need to return any value due to the object is not a platform
- // object. The execution reaches here when Object.getOwnPropertyDescriptor
- // gets called on native object prototypes.
- return true;
- }
-
- MozjsGlobalEnvironment* global_environment =
- static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context));
- WrapperFactory* wrapper_factory = global_environment->wrapper_factory();
- if (!wrapper_factory->DoesObjectImplementInterface(
- object, base::GetTypeId<BooleanTypeTestInterface>())) {
- MozjsExceptionState exception(context);
- exception.SetSimpleException(script::kDoesNotImplementInterface);
- return false;
- }
- MozjsExceptionState exception_state(context);
- JS::RootedValue result_value(context);
-
- WrapperPrivate* wrapper_private =
- WrapperPrivate::GetFromObject(context, object);
- BooleanTypeTestInterface* impl =
- wrapper_private->wrappable<BooleanTypeTestInterface>().get();
-
- if (!exception_state.is_exception_set()) {
- ToJSValue(context,
- impl->BooleanReturnOperation(),
- &result_value);
- }
- if (!exception_state.is_exception_set()) {
- args.rval().set(result_value);
- }
- return !exception_state.is_exception_set();
-}
-
-
-const JSPropertySpec prototype_properties[] = {
- { // Read/Write property
- "booleanProperty", 0,
- JSPROP_SHARED | JSPROP_ENUMERATE,
- JSOP_WRAPPER(&get_booleanProperty),
- JSOP_WRAPPER(&set_booleanProperty),
- },
- JS_PS_END
-};
-
-const JSFunctionSpec prototype_functions[] = {
- {
- "booleanArgumentOperation",
- JSOP_WRAPPER(&fcn_booleanArgumentOperation),
- 1,
- JSPROP_ENUMERATE,
- NULL,
- },
- {
- "booleanReturnOperation",
- JSOP_WRAPPER(&fcn_booleanReturnOperation),
- 0,
- JSPROP_ENUMERATE,
- NULL,
- },
- JS_FS_END
-};
-
-const JSPropertySpec interface_object_properties[] = {
- JS_PS_END
-};
-
-const JSFunctionSpec interface_object_functions[] = {
- JS_FS_END
-};
-
-const JSPropertySpec own_properties[] = {
- JS_PS_END
-};
-
-void InitializePrototypeAndInterfaceObject(
- InterfaceData* interface_data, JSContext* context,
- JS::HandleObject global_object) {
- DCHECK(!interface_data->prototype);
- DCHECK(!interface_data->interface_object);
- DCHECK(JS_IsGlobalObject(global_object));
-
- JS::RootedObject parent_prototype(
- context, JS_GetObjectPrototype(context, global_object));
- DCHECK(parent_prototype);
-
- // Create the Prototype object.
- interface_data->prototype = JS_NewObjectWithGivenProto(
- context, &interface_data->prototype_class_definition, parent_prototype,
- NULL);
- bool success = JS_DefineProperties(
- context, interface_data->prototype, prototype_properties);
- DCHECK(success);
- success = JS_DefineFunctions(
- context, interface_data->prototype, prototype_functions);
- DCHECK(success);
-
- JS::RootedObject function_prototype(
- context, JS_GetFunctionPrototype(context, global_object));
- DCHECK(function_prototype);
- // Create the Interface object.
- interface_data->interface_object = JS_NewObjectWithGivenProto(
- context, &interface_data->interface_object_class_definition,
- function_prototype, NULL);
-
- // Add the InterfaceObject.name property.
- JS::RootedObject rooted_interface_object(
- context, interface_data->interface_object);
- JS::RootedValue name_value(context);
- const char name[] =
- "BooleanTypeTestInterface";
- name_value.setString(JS_NewStringCopyZ(context, name));
- success =
- JS_DefineProperty(context, rooted_interface_object, "name", name_value,
- JS_PropertyStub, JS_StrictPropertyStub,
- JSPROP_READONLY);
- DCHECK(success);
-
- // Define interface object properties (including constants).
- success = JS_DefineProperties(context, rooted_interface_object,
- interface_object_properties);
- DCHECK(success);
- // Define interface object functions (static).
- success = JS_DefineFunctions(context, rooted_interface_object,
- interface_object_functions);
- DCHECK(success);
-
-
- // Set the Prototype.constructor and Constructor.prototype properties.
- DCHECK(interface_data->interface_object);
- DCHECK(interface_data->prototype);
- JS::RootedObject rooted_prototype(context, interface_data->prototype);
- success = JS_LinkConstructorAndPrototype(
- context,
- rooted_interface_object,
- rooted_prototype);
- DCHECK(success);
-}
-
-InterfaceData* GetInterfaceData(JSContext* context) {
- MozjsGlobalEnvironment* global_environment =
- static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context));
- // Use the address of the properties definition for this interface as a
- // unique key for looking up the InterfaceData for this interface.
- intptr_t key = reinterpret_cast<intptr_t>(&own_properties);
- InterfaceData* interface_data = global_environment->GetInterfaceData(key);
- if (!interface_data) {
- interface_data = CreateCachedInterfaceData();
- DCHECK(interface_data);
- global_environment->CacheInterfaceData(key, interface_data);
- DCHECK_EQ(interface_data, global_environment->GetInterfaceData(key));
- }
- return interface_data;
-}
-
-} // namespace
-
-// static
-JSObject* MozjsBooleanTypeTestInterface::CreateProxy(
- JSContext* context, const scoped_refptr<Wrappable>& wrappable) {
- DCHECK(MozjsGlobalEnvironment::GetFromContext(context));
- JS::RootedObject global_object(
- context,
- MozjsGlobalEnvironment::GetFromContext(context)->global_object());
- DCHECK(global_object);
-
- InterfaceData* interface_data = GetInterfaceData(context);
- JS::RootedObject prototype(context, GetPrototype(context, global_object));
- DCHECK(prototype);
- JS::RootedObject new_object(context, JS_NewObjectWithGivenProto(
- context, &interface_data->instance_class_definition, prototype, NULL));
- DCHECK(new_object);
- JS::RootedObject proxy(context,
- ProxyHandler::NewProxy(context, new_object, prototype, NULL,
- proxy_handler.Pointer()));
- WrapperPrivate::AddPrivateData(context, proxy, wrappable);
- return proxy;
-}
-
-//static
-const JSClass* MozjsBooleanTypeTestInterface::PrototypeClass(
- JSContext* context) {
- DCHECK(MozjsGlobalEnvironment::GetFromContext(context));
- JS::RootedObject global_object(
- context,
- MozjsGlobalEnvironment::GetFromContext(context)->global_object());
- DCHECK(global_object);
-
- JS::RootedObject prototype(context, GetPrototype(context, global_object));
- JSClass* proto_class = JS_GetClass(*prototype.address());
- return proto_class;
-}
-
-// static
-JSObject* MozjsBooleanTypeTestInterface::GetPrototype(
- JSContext* context, JS::HandleObject global_object) {
- DCHECK(JS_IsGlobalObject(global_object));
-
- InterfaceData* interface_data = GetInterfaceData(context);
- if (!interface_data->prototype) {
- // Create new prototype that has all the props and methods
- InitializePrototypeAndInterfaceObject(
- interface_data, context, global_object);
- }
- DCHECK(interface_data->prototype);
- return interface_data->prototype;
-}
-
-// static
-JSObject* MozjsBooleanTypeTestInterface::GetInterfaceObject(
- JSContext* context, JS::HandleObject global_object) {
- DCHECK(JS_IsGlobalObject(global_object));
-
- InterfaceData* interface_data = GetInterfaceData(context);
- if (!interface_data->interface_object) {
- InitializePrototypeAndInterfaceObject(
- interface_data, context, global_object);
- }
- DCHECK(interface_data->interface_object);
- return interface_data->interface_object;
-}
-
-
-namespace {
-} // namespace
-
-
-} // namespace testing
-} // namespace bindings
-} // namespace cobalt
diff --git a/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_boolean_type_test_interface.h b/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_boolean_type_test_interface.h
deleted file mode 100644
index 18e3077..0000000
--- a/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_boolean_type_test_interface.h
+++ /dev/null
@@ -1,52 +0,0 @@
-// Copyright 2017 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/mozjs/templates/interface.h.template
-
-#ifndef MozjsBooleanTypeTestInterface_h
-#define MozjsBooleanTypeTestInterface_h
-
-#include "base/hash_tables.h"
-#include "base/lazy_instance.h"
-#include "base/memory/ref_counted.h"
-#include "base/threading/thread_checker.h"
-#include "cobalt/base/polymorphic_downcast.h"
-#include "cobalt/script/wrappable.h"
-#include "cobalt/bindings/testing/boolean_type_test_interface.h"
-
-#include "third_party/mozjs/js/src/jsapi.h"
-
-namespace cobalt {
-namespace bindings {
-namespace testing {
-
-class MozjsBooleanTypeTestInterface {
- public:
- static JSObject* CreateProxy(JSContext* context,
- const scoped_refptr<script::Wrappable>& wrappable);
- static const JSClass* PrototypeClass(JSContext* context);
- static JSObject* GetPrototype(JSContext* context,
- JS::HandleObject global_object);
- static JSObject* GetInterfaceObject(JSContext* context,
- JS::HandleObject global_object);
-};
-
-} // namespace testing
-} // namespace bindings
-} // namespace cobalt
-
-#endif // MozjsBooleanTypeTestInterface_h
diff --git a/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_callback_function_interface.cc b/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_callback_function_interface.cc
deleted file mode 100644
index 5c0218b..0000000
--- a/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_callback_function_interface.cc
+++ /dev/null
@@ -1,904 +0,0 @@
-// Copyright 2017 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/mozjs/templates/interface.cc.template
-
-#include "cobalt/bindings/testing/mozjs_callback_function_interface.h"
-
-#include "base/debug/trace_event.h"
-#include "cobalt/base/polymorphic_downcast.h"
-#include "cobalt/script/global_environment.h"
-#include "cobalt/script/opaque_handle.h"
-#include "cobalt/script/script_value.h"
-#include "cobalt/bindings/testing/arbitrary_interface.h"
-#include "cobalt/bindings/testing/mozjs_arbitrary_interface.h"
-
-#include "mozjs_gen_type_conversion.h"
-
-#include "base/lazy_instance.h"
-#include "cobalt/script/exception_state.h"
-#include "cobalt/script/mozjs/callback_function_conversion.h"
-#include "cobalt/script/mozjs/conversion_helpers.h"
-#include "cobalt/script/mozjs/mozjs_callback_function.h"
-#include "cobalt/script/mozjs/mozjs_exception_state.h"
-#include "cobalt/script/mozjs/mozjs_global_environment.h"
-#include "cobalt/script/mozjs/mozjs_object_handle.h"
-#include "cobalt/script/mozjs/mozjs_property_enumerator.h"
-#include "cobalt/script/mozjs/mozjs_user_object_holder.h"
-#include "cobalt/script/mozjs/mozjs_value_handle.h"
-#include "cobalt/script/mozjs/native_promise.h"
-#include "cobalt/script/mozjs/proxy_handler.h"
-#include "cobalt/script/mozjs/type_traits.h"
-#include "cobalt/script/mozjs/wrapper_factory.h"
-#include "cobalt/script/mozjs/wrapper_private.h"
-#include "cobalt/script/property_enumerator.h"
-#include "cobalt/script/sequence.h"
-#include "third_party/mozjs/js/src/jsapi.h"
-#include "third_party/mozjs/js/src/jsfriendapi.h"
-
-namespace {
-using cobalt::bindings::testing::CallbackFunctionInterface;
-using cobalt::bindings::testing::MozjsCallbackFunctionInterface;
-using cobalt::bindings::testing::ArbitraryInterface;
-using cobalt::bindings::testing::MozjsArbitraryInterface;
-using cobalt::script::CallbackInterfaceTraits;
-using cobalt::script::GlobalEnvironment;
-using cobalt::script::OpaqueHandle;
-using cobalt::script::OpaqueHandleHolder;
-using cobalt::script::ScriptValue;
-using cobalt::script::ValueHandle;
-using cobalt::script::Wrappable;
-
-using cobalt::script::CallbackFunction;
-using cobalt::script::CallbackInterfaceTraits;
-using cobalt::script::ExceptionState;
-using cobalt::script::Wrappable;
-using cobalt::script::mozjs::FromJSValue;
-using cobalt::script::mozjs::InterfaceData;
-using cobalt::script::mozjs::MozjsCallbackFunction;
-using cobalt::script::mozjs::MozjsExceptionState;
-using cobalt::script::mozjs::MozjsGlobalEnvironment;
-using cobalt::script::mozjs::MozjsPropertyEnumerator;
-using cobalt::script::mozjs::MozjsUserObjectHolder;
-using cobalt::script::mozjs::ProxyHandler;
-using cobalt::script::mozjs::ToJSValue;
-using cobalt::script::mozjs::TypeTraits;
-using cobalt::script::mozjs::WrapperFactory;
-using cobalt::script::mozjs::WrapperPrivate;
-using cobalt::script::mozjs::kConversionFlagClamped;
-using cobalt::script::mozjs::kConversionFlagNullable;
-using cobalt::script::mozjs::kConversionFlagRestricted;
-using cobalt::script::mozjs::kConversionFlagTreatNullAsEmptyString;
-using cobalt::script::mozjs::kConversionFlagTreatUndefinedAsEmptyString;
-using cobalt::script::mozjs::kNoConversionFlags;
-} // namespace
-
-namespace cobalt {
-namespace bindings {
-namespace testing {
-
-namespace {
-
-class MozjsCallbackFunctionInterfaceHandler : public ProxyHandler {
- public:
- MozjsCallbackFunctionInterfaceHandler()
- : ProxyHandler(indexed_property_hooks, named_property_hooks) {}
-
- private:
- static NamedPropertyHooks named_property_hooks;
- static IndexedPropertyHooks indexed_property_hooks;
-};
-
-ProxyHandler::NamedPropertyHooks
-MozjsCallbackFunctionInterfaceHandler::named_property_hooks = {
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
-};
-ProxyHandler::IndexedPropertyHooks
-MozjsCallbackFunctionInterfaceHandler::indexed_property_hooks = {
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
-};
-
-static base::LazyInstance<MozjsCallbackFunctionInterfaceHandler>
- proxy_handler;
-
-JSBool HasInstance(JSContext *context, JS::HandleObject type,
- JS::MutableHandleValue vp, JSBool *success) {
- JS::RootedObject global_object(
- context, JS_GetGlobalForObject(context, type));
- DCHECK(global_object);
-
- JS::RootedObject prototype(
- context, MozjsCallbackFunctionInterface::GetPrototype(context, global_object));
-
- // |IsDelegate| walks the prototype chain of an object returning true if
- // .prototype is found.
- bool is_delegate;
- if (!IsDelegate(context, prototype, vp, &is_delegate)) {
- *success = false;
- return false;
- }
-
- *success = is_delegate;
- return true;
-}
-
-InterfaceData* CreateCachedInterfaceData() {
- InterfaceData* interface_data = new InterfaceData();
- memset(&interface_data->instance_class_definition, 0,
- sizeof(interface_data->instance_class_definition));
- memset(&interface_data->prototype_class_definition, 0,
- sizeof(interface_data->prototype_class_definition));
- memset(&interface_data->interface_object_class_definition, 0,
- sizeof(interface_data->interface_object_class_definition));
-
- JSClass* instance_class = &interface_data->instance_class_definition;
- const int kGlobalFlags = 0;
- instance_class->name = "CallbackFunctionInterface";
- instance_class->flags = kGlobalFlags | JSCLASS_HAS_PRIVATE;
- instance_class->addProperty = JS_PropertyStub;
- instance_class->delProperty = JS_DeletePropertyStub;
- instance_class->getProperty = JS_PropertyStub;
- instance_class->setProperty = JS_StrictPropertyStub;
- instance_class->enumerate = JS_EnumerateStub;
- instance_class->resolve = JS_ResolveStub;
- instance_class->convert = JS_ConvertStub;
- // Function to be called before on object of this class is garbage collected.
- instance_class->finalize = &WrapperPrivate::Finalizer;
- // Called to trace objects that can be referenced from this object.
- instance_class->trace = &WrapperPrivate::Trace;
-
- JSClass* prototype_class = &interface_data->prototype_class_definition;
- prototype_class->name = "CallbackFunctionInterfacePrototype";
- prototype_class->flags = 0;
- prototype_class->addProperty = JS_PropertyStub;
- prototype_class->delProperty = JS_DeletePropertyStub;
- prototype_class->getProperty = JS_PropertyStub;
- prototype_class->setProperty = JS_StrictPropertyStub;
- prototype_class->enumerate = JS_EnumerateStub;
- prototype_class->resolve = JS_ResolveStub;
- prototype_class->convert = JS_ConvertStub;
-
- JSClass* interface_object_class =
- &interface_data->interface_object_class_definition;
- interface_object_class->name = "CallbackFunctionInterfaceConstructor";
- interface_object_class->flags = 0;
- interface_object_class->addProperty = JS_PropertyStub;
- interface_object_class->delProperty = JS_DeletePropertyStub;
- interface_object_class->getProperty = JS_PropertyStub;
- interface_object_class->setProperty = JS_StrictPropertyStub;
- interface_object_class->enumerate = JS_EnumerateStub;
- interface_object_class->resolve = JS_ResolveStub;
- interface_object_class->convert = JS_ConvertStub;
- interface_object_class->hasInstance = &HasInstance;
- return interface_data;
-}
-
-JSBool get_callbackAttribute(
- JSContext* context, JS::HandleObject object, JS::HandleId id,
- JS::MutableHandleValue vp) {
- const JSClass* proto_class =
- MozjsCallbackFunctionInterface::PrototypeClass(context);
- if (proto_class == JS_GetClass(object)) {
- // Simply returns true if the object is this class's prototype object.
- // There is no need to return any value due to the object is not a platform
- // object. The execution reaches here when Object.getOwnPropertyDescriptor
- // gets called on native object prototypes.
- return true;
- }
-
- MozjsGlobalEnvironment* global_environment =
- static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context));
- WrapperFactory* wrapper_factory = global_environment->wrapper_factory();
- if (!wrapper_factory->DoesObjectImplementInterface(
- object, base::GetTypeId<CallbackFunctionInterface>())) {
- MozjsExceptionState exception(context);
- exception.SetSimpleException(script::kDoesNotImplementInterface);
- return false;
- }
- MozjsExceptionState exception_state(context);
- JS::RootedValue result_value(context);
-
- WrapperPrivate* wrapper_private =
- WrapperPrivate::GetFromObject(context, object);
- CallbackFunctionInterface* impl =
- wrapper_private->wrappable<CallbackFunctionInterface>().get();
-
- if (!exception_state.is_exception_set()) {
- ToJSValue(context,
- impl->callback_attribute(),
- &result_value);
- }
- if (!exception_state.is_exception_set()) {
- vp.set(result_value);
- }
- return !exception_state.is_exception_set();
-}
-
-JSBool set_callbackAttribute(
- JSContext* context, JS::HandleObject object, JS::HandleId id,
- JSBool strict, JS::MutableHandleValue vp) {
- const JSClass* proto_class =
- MozjsCallbackFunctionInterface::PrototypeClass(context);
- if (proto_class == JS_GetClass(object)) {
- // Simply returns true if the object is this class's prototype object.
- // There is no need to return any value due to the object is not a platform
- // object. The execution reaches here when Object.getOwnPropertyDescriptor
- // gets called on native object prototypes.
- return true;
- }
-
- MozjsGlobalEnvironment* global_environment =
- static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context));
- WrapperFactory* wrapper_factory = global_environment->wrapper_factory();
- if (!wrapper_factory->DoesObjectImplementInterface(
- object, base::GetTypeId<CallbackFunctionInterface>())) {
- MozjsExceptionState exception(context);
- exception.SetSimpleException(script::kDoesNotImplementInterface);
- return false;
- }
- MozjsExceptionState exception_state(context);
- JS::RootedValue result_value(context);
-
- WrapperPrivate* wrapper_private =
- WrapperPrivate::GetFromObject(context, object);
- CallbackFunctionInterface* impl =
- wrapper_private->wrappable<CallbackFunctionInterface>().get();
- TypeTraits<CallbackFunctionInterface::VoidFunction >::ConversionType value;
- FromJSValue(context, vp, kNoConversionFlags, &exception_state,
- &value);
- if (exception_state.is_exception_set()) {
- return false;
- }
-
- impl->set_callback_attribute(value);
- result_value.set(JS::UndefinedHandleValue);
- return !exception_state.is_exception_set();
-}
-
-JSBool get_nullableCallbackAttribute(
- JSContext* context, JS::HandleObject object, JS::HandleId id,
- JS::MutableHandleValue vp) {
- const JSClass* proto_class =
- MozjsCallbackFunctionInterface::PrototypeClass(context);
- if (proto_class == JS_GetClass(object)) {
- // Simply returns true if the object is this class's prototype object.
- // There is no need to return any value due to the object is not a platform
- // object. The execution reaches here when Object.getOwnPropertyDescriptor
- // gets called on native object prototypes.
- return true;
- }
-
- MozjsGlobalEnvironment* global_environment =
- static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context));
- WrapperFactory* wrapper_factory = global_environment->wrapper_factory();
- if (!wrapper_factory->DoesObjectImplementInterface(
- object, base::GetTypeId<CallbackFunctionInterface>())) {
- MozjsExceptionState exception(context);
- exception.SetSimpleException(script::kDoesNotImplementInterface);
- return false;
- }
- MozjsExceptionState exception_state(context);
- JS::RootedValue result_value(context);
-
- WrapperPrivate* wrapper_private =
- WrapperPrivate::GetFromObject(context, object);
- CallbackFunctionInterface* impl =
- wrapper_private->wrappable<CallbackFunctionInterface>().get();
-
- if (!exception_state.is_exception_set()) {
- ToJSValue(context,
- impl->nullable_callback_attribute(),
- &result_value);
- }
- if (!exception_state.is_exception_set()) {
- vp.set(result_value);
- }
- return !exception_state.is_exception_set();
-}
-
-JSBool set_nullableCallbackAttribute(
- JSContext* context, JS::HandleObject object, JS::HandleId id,
- JSBool strict, JS::MutableHandleValue vp) {
- const JSClass* proto_class =
- MozjsCallbackFunctionInterface::PrototypeClass(context);
- if (proto_class == JS_GetClass(object)) {
- // Simply returns true if the object is this class's prototype object.
- // There is no need to return any value due to the object is not a platform
- // object. The execution reaches here when Object.getOwnPropertyDescriptor
- // gets called on native object prototypes.
- return true;
- }
-
- MozjsGlobalEnvironment* global_environment =
- static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context));
- WrapperFactory* wrapper_factory = global_environment->wrapper_factory();
- if (!wrapper_factory->DoesObjectImplementInterface(
- object, base::GetTypeId<CallbackFunctionInterface>())) {
- MozjsExceptionState exception(context);
- exception.SetSimpleException(script::kDoesNotImplementInterface);
- return false;
- }
- MozjsExceptionState exception_state(context);
- JS::RootedValue result_value(context);
-
- WrapperPrivate* wrapper_private =
- WrapperPrivate::GetFromObject(context, object);
- CallbackFunctionInterface* impl =
- wrapper_private->wrappable<CallbackFunctionInterface>().get();
- TypeTraits<CallbackFunctionInterface::VoidFunction >::ConversionType value;
- FromJSValue(context, vp, (kConversionFlagNullable), &exception_state,
- &value);
- if (exception_state.is_exception_set()) {
- return false;
- }
-
- impl->set_nullable_callback_attribute(value);
- result_value.set(JS::UndefinedHandleValue);
- return !exception_state.is_exception_set();
-}
-
-JSBool fcn_takesFunctionThatReturnsString(
- JSContext* context, uint32_t argc, JS::Value *vp) {
- JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
- // Compute the 'this' value.
- JS::RootedValue this_value(context, JS_ComputeThis(context, vp));
- // 'this' should be an object.
- JS::RootedObject object(context);
- if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) {
- return false;
- }
- if (!JS_ValueToObject(context, this_value, object.address())) {
- NOTREACHED();
- return false;
- }
- const JSClass* proto_class =
- MozjsCallbackFunctionInterface::PrototypeClass(context);
- if (proto_class == JS_GetClass(object)) {
- // Simply returns true if the object is this class's prototype object.
- // There is no need to return any value due to the object is not a platform
- // object. The execution reaches here when Object.getOwnPropertyDescriptor
- // gets called on native object prototypes.
- return true;
- }
-
- MozjsGlobalEnvironment* global_environment =
- static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context));
- WrapperFactory* wrapper_factory = global_environment->wrapper_factory();
- if (!wrapper_factory->DoesObjectImplementInterface(
- object, base::GetTypeId<CallbackFunctionInterface>())) {
- MozjsExceptionState exception(context);
- exception.SetSimpleException(script::kDoesNotImplementInterface);
- return false;
- }
- MozjsExceptionState exception_state(context);
- JS::RootedValue result_value(context);
-
- WrapperPrivate* wrapper_private =
- WrapperPrivate::GetFromObject(context, object);
- CallbackFunctionInterface* impl =
- wrapper_private->wrappable<CallbackFunctionInterface>().get();
- const size_t kMinArguments = 1;
- if (args.length() < kMinArguments) {
- exception_state.SetSimpleException(script::kInvalidNumberOfArguments);
- return false;
- }
- // Non-optional arguments
- TypeTraits<CallbackFunctionInterface::FunctionThatReturnsString >::ConversionType cb;
-
- DCHECK_LT(0, args.length());
- JS::RootedValue non_optional_value0(
- context, args[0]);
- FromJSValue(context,
- non_optional_value0,
- kNoConversionFlags,
- &exception_state, &cb);
- if (exception_state.is_exception_set()) {
- return false;
- }
-
- impl->TakesFunctionThatReturnsString(cb);
- result_value.set(JS::UndefinedHandleValue);
- return !exception_state.is_exception_set();
-}
-
-JSBool fcn_takesFunctionWithNullableParameters(
- JSContext* context, uint32_t argc, JS::Value *vp) {
- JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
- // Compute the 'this' value.
- JS::RootedValue this_value(context, JS_ComputeThis(context, vp));
- // 'this' should be an object.
- JS::RootedObject object(context);
- if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) {
- return false;
- }
- if (!JS_ValueToObject(context, this_value, object.address())) {
- NOTREACHED();
- return false;
- }
- const JSClass* proto_class =
- MozjsCallbackFunctionInterface::PrototypeClass(context);
- if (proto_class == JS_GetClass(object)) {
- // Simply returns true if the object is this class's prototype object.
- // There is no need to return any value due to the object is not a platform
- // object. The execution reaches here when Object.getOwnPropertyDescriptor
- // gets called on native object prototypes.
- return true;
- }
-
- MozjsGlobalEnvironment* global_environment =
- static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context));
- WrapperFactory* wrapper_factory = global_environment->wrapper_factory();
- if (!wrapper_factory->DoesObjectImplementInterface(
- object, base::GetTypeId<CallbackFunctionInterface>())) {
- MozjsExceptionState exception(context);
- exception.SetSimpleException(script::kDoesNotImplementInterface);
- return false;
- }
- MozjsExceptionState exception_state(context);
- JS::RootedValue result_value(context);
-
- WrapperPrivate* wrapper_private =
- WrapperPrivate::GetFromObject(context, object);
- CallbackFunctionInterface* impl =
- wrapper_private->wrappable<CallbackFunctionInterface>().get();
- const size_t kMinArguments = 1;
- if (args.length() < kMinArguments) {
- exception_state.SetSimpleException(script::kInvalidNumberOfArguments);
- return false;
- }
- // Non-optional arguments
- TypeTraits<CallbackFunctionInterface::FunctionWithNullableParameters >::ConversionType cb;
-
- DCHECK_LT(0, args.length());
- JS::RootedValue non_optional_value0(
- context, args[0]);
- FromJSValue(context,
- non_optional_value0,
- kNoConversionFlags,
- &exception_state, &cb);
- if (exception_state.is_exception_set()) {
- return false;
- }
-
- impl->TakesFunctionWithNullableParameters(cb);
- result_value.set(JS::UndefinedHandleValue);
- return !exception_state.is_exception_set();
-}
-
-JSBool fcn_takesFunctionWithOneParameter(
- JSContext* context, uint32_t argc, JS::Value *vp) {
- JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
- // Compute the 'this' value.
- JS::RootedValue this_value(context, JS_ComputeThis(context, vp));
- // 'this' should be an object.
- JS::RootedObject object(context);
- if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) {
- return false;
- }
- if (!JS_ValueToObject(context, this_value, object.address())) {
- NOTREACHED();
- return false;
- }
- const JSClass* proto_class =
- MozjsCallbackFunctionInterface::PrototypeClass(context);
- if (proto_class == JS_GetClass(object)) {
- // Simply returns true if the object is this class's prototype object.
- // There is no need to return any value due to the object is not a platform
- // object. The execution reaches here when Object.getOwnPropertyDescriptor
- // gets called on native object prototypes.
- return true;
- }
-
- MozjsGlobalEnvironment* global_environment =
- static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context));
- WrapperFactory* wrapper_factory = global_environment->wrapper_factory();
- if (!wrapper_factory->DoesObjectImplementInterface(
- object, base::GetTypeId<CallbackFunctionInterface>())) {
- MozjsExceptionState exception(context);
- exception.SetSimpleException(script::kDoesNotImplementInterface);
- return false;
- }
- MozjsExceptionState exception_state(context);
- JS::RootedValue result_value(context);
-
- WrapperPrivate* wrapper_private =
- WrapperPrivate::GetFromObject(context, object);
- CallbackFunctionInterface* impl =
- wrapper_private->wrappable<CallbackFunctionInterface>().get();
- const size_t kMinArguments = 1;
- if (args.length() < kMinArguments) {
- exception_state.SetSimpleException(script::kInvalidNumberOfArguments);
- return false;
- }
- // Non-optional arguments
- TypeTraits<CallbackFunctionInterface::FunctionWithOneParameter >::ConversionType cb;
-
- DCHECK_LT(0, args.length());
- JS::RootedValue non_optional_value0(
- context, args[0]);
- FromJSValue(context,
- non_optional_value0,
- kNoConversionFlags,
- &exception_state, &cb);
- if (exception_state.is_exception_set()) {
- return false;
- }
-
- impl->TakesFunctionWithOneParameter(cb);
- result_value.set(JS::UndefinedHandleValue);
- return !exception_state.is_exception_set();
-}
-
-JSBool fcn_takesFunctionWithSeveralParameters(
- JSContext* context, uint32_t argc, JS::Value *vp) {
- JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
- // Compute the 'this' value.
- JS::RootedValue this_value(context, JS_ComputeThis(context, vp));
- // 'this' should be an object.
- JS::RootedObject object(context);
- if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) {
- return false;
- }
- if (!JS_ValueToObject(context, this_value, object.address())) {
- NOTREACHED();
- return false;
- }
- const JSClass* proto_class =
- MozjsCallbackFunctionInterface::PrototypeClass(context);
- if (proto_class == JS_GetClass(object)) {
- // Simply returns true if the object is this class's prototype object.
- // There is no need to return any value due to the object is not a platform
- // object. The execution reaches here when Object.getOwnPropertyDescriptor
- // gets called on native object prototypes.
- return true;
- }
-
- MozjsGlobalEnvironment* global_environment =
- static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context));
- WrapperFactory* wrapper_factory = global_environment->wrapper_factory();
- if (!wrapper_factory->DoesObjectImplementInterface(
- object, base::GetTypeId<CallbackFunctionInterface>())) {
- MozjsExceptionState exception(context);
- exception.SetSimpleException(script::kDoesNotImplementInterface);
- return false;
- }
- MozjsExceptionState exception_state(context);
- JS::RootedValue result_value(context);
-
- WrapperPrivate* wrapper_private =
- WrapperPrivate::GetFromObject(context, object);
- CallbackFunctionInterface* impl =
- wrapper_private->wrappable<CallbackFunctionInterface>().get();
- const size_t kMinArguments = 1;
- if (args.length() < kMinArguments) {
- exception_state.SetSimpleException(script::kInvalidNumberOfArguments);
- return false;
- }
- // Non-optional arguments
- TypeTraits<CallbackFunctionInterface::FunctionWithSeveralParameters >::ConversionType cb;
-
- DCHECK_LT(0, args.length());
- JS::RootedValue non_optional_value0(
- context, args[0]);
- FromJSValue(context,
- non_optional_value0,
- kNoConversionFlags,
- &exception_state, &cb);
- if (exception_state.is_exception_set()) {
- return false;
- }
-
- impl->TakesFunctionWithSeveralParameters(cb);
- result_value.set(JS::UndefinedHandleValue);
- return !exception_state.is_exception_set();
-}
-
-JSBool fcn_takesVoidFunction(
- JSContext* context, uint32_t argc, JS::Value *vp) {
- JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
- // Compute the 'this' value.
- JS::RootedValue this_value(context, JS_ComputeThis(context, vp));
- // 'this' should be an object.
- JS::RootedObject object(context);
- if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) {
- return false;
- }
- if (!JS_ValueToObject(context, this_value, object.address())) {
- NOTREACHED();
- return false;
- }
- const JSClass* proto_class =
- MozjsCallbackFunctionInterface::PrototypeClass(context);
- if (proto_class == JS_GetClass(object)) {
- // Simply returns true if the object is this class's prototype object.
- // There is no need to return any value due to the object is not a platform
- // object. The execution reaches here when Object.getOwnPropertyDescriptor
- // gets called on native object prototypes.
- return true;
- }
-
- MozjsGlobalEnvironment* global_environment =
- static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context));
- WrapperFactory* wrapper_factory = global_environment->wrapper_factory();
- if (!wrapper_factory->DoesObjectImplementInterface(
- object, base::GetTypeId<CallbackFunctionInterface>())) {
- MozjsExceptionState exception(context);
- exception.SetSimpleException(script::kDoesNotImplementInterface);
- return false;
- }
- MozjsExceptionState exception_state(context);
- JS::RootedValue result_value(context);
-
- WrapperPrivate* wrapper_private =
- WrapperPrivate::GetFromObject(context, object);
- CallbackFunctionInterface* impl =
- wrapper_private->wrappable<CallbackFunctionInterface>().get();
- const size_t kMinArguments = 1;
- if (args.length() < kMinArguments) {
- exception_state.SetSimpleException(script::kInvalidNumberOfArguments);
- return false;
- }
- // Non-optional arguments
- TypeTraits<CallbackFunctionInterface::VoidFunction >::ConversionType cb;
-
- DCHECK_LT(0, args.length());
- JS::RootedValue non_optional_value0(
- context, args[0]);
- FromJSValue(context,
- non_optional_value0,
- kNoConversionFlags,
- &exception_state, &cb);
- if (exception_state.is_exception_set()) {
- return false;
- }
-
- impl->TakesVoidFunction(cb);
- result_value.set(JS::UndefinedHandleValue);
- return !exception_state.is_exception_set();
-}
-
-
-const JSPropertySpec prototype_properties[] = {
- { // Read/Write property
- "callbackAttribute", 0,
- JSPROP_SHARED | JSPROP_ENUMERATE,
- JSOP_WRAPPER(&get_callbackAttribute),
- JSOP_WRAPPER(&set_callbackAttribute),
- },
- { // Read/Write property
- "nullableCallbackAttribute", 0,
- JSPROP_SHARED | JSPROP_ENUMERATE,
- JSOP_WRAPPER(&get_nullableCallbackAttribute),
- JSOP_WRAPPER(&set_nullableCallbackAttribute),
- },
- JS_PS_END
-};
-
-const JSFunctionSpec prototype_functions[] = {
- {
- "takesFunctionThatReturnsString",
- JSOP_WRAPPER(&fcn_takesFunctionThatReturnsString),
- 1,
- JSPROP_ENUMERATE,
- NULL,
- },
- {
- "takesFunctionWithNullableParameters",
- JSOP_WRAPPER(&fcn_takesFunctionWithNullableParameters),
- 1,
- JSPROP_ENUMERATE,
- NULL,
- },
- {
- "takesFunctionWithOneParameter",
- JSOP_WRAPPER(&fcn_takesFunctionWithOneParameter),
- 1,
- JSPROP_ENUMERATE,
- NULL,
- },
- {
- "takesFunctionWithSeveralParameters",
- JSOP_WRAPPER(&fcn_takesFunctionWithSeveralParameters),
- 1,
- JSPROP_ENUMERATE,
- NULL,
- },
- {
- "takesVoidFunction",
- JSOP_WRAPPER(&fcn_takesVoidFunction),
- 1,
- JSPROP_ENUMERATE,
- NULL,
- },
- JS_FS_END
-};
-
-const JSPropertySpec interface_object_properties[] = {
- JS_PS_END
-};
-
-const JSFunctionSpec interface_object_functions[] = {
- JS_FS_END
-};
-
-const JSPropertySpec own_properties[] = {
- JS_PS_END
-};
-
-void InitializePrototypeAndInterfaceObject(
- InterfaceData* interface_data, JSContext* context,
- JS::HandleObject global_object) {
- DCHECK(!interface_data->prototype);
- DCHECK(!interface_data->interface_object);
- DCHECK(JS_IsGlobalObject(global_object));
-
- JS::RootedObject parent_prototype(
- context, JS_GetObjectPrototype(context, global_object));
- DCHECK(parent_prototype);
-
- // Create the Prototype object.
- interface_data->prototype = JS_NewObjectWithGivenProto(
- context, &interface_data->prototype_class_definition, parent_prototype,
- NULL);
- bool success = JS_DefineProperties(
- context, interface_data->prototype, prototype_properties);
- DCHECK(success);
- success = JS_DefineFunctions(
- context, interface_data->prototype, prototype_functions);
- DCHECK(success);
-
- JS::RootedObject function_prototype(
- context, JS_GetFunctionPrototype(context, global_object));
- DCHECK(function_prototype);
- // Create the Interface object.
- interface_data->interface_object = JS_NewObjectWithGivenProto(
- context, &interface_data->interface_object_class_definition,
- function_prototype, NULL);
-
- // Add the InterfaceObject.name property.
- JS::RootedObject rooted_interface_object(
- context, interface_data->interface_object);
- JS::RootedValue name_value(context);
- const char name[] =
- "CallbackFunctionInterface";
- name_value.setString(JS_NewStringCopyZ(context, name));
- success =
- JS_DefineProperty(context, rooted_interface_object, "name", name_value,
- JS_PropertyStub, JS_StrictPropertyStub,
- JSPROP_READONLY);
- DCHECK(success);
-
- // Define interface object properties (including constants).
- success = JS_DefineProperties(context, rooted_interface_object,
- interface_object_properties);
- DCHECK(success);
- // Define interface object functions (static).
- success = JS_DefineFunctions(context, rooted_interface_object,
- interface_object_functions);
- DCHECK(success);
-
-
- // Set the Prototype.constructor and Constructor.prototype properties.
- DCHECK(interface_data->interface_object);
- DCHECK(interface_data->prototype);
- JS::RootedObject rooted_prototype(context, interface_data->prototype);
- success = JS_LinkConstructorAndPrototype(
- context,
- rooted_interface_object,
- rooted_prototype);
- DCHECK(success);
-}
-
-InterfaceData* GetInterfaceData(JSContext* context) {
- MozjsGlobalEnvironment* global_environment =
- static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context));
- // Use the address of the properties definition for this interface as a
- // unique key for looking up the InterfaceData for this interface.
- intptr_t key = reinterpret_cast<intptr_t>(&own_properties);
- InterfaceData* interface_data = global_environment->GetInterfaceData(key);
- if (!interface_data) {
- interface_data = CreateCachedInterfaceData();
- DCHECK(interface_data);
- global_environment->CacheInterfaceData(key, interface_data);
- DCHECK_EQ(interface_data, global_environment->GetInterfaceData(key));
- }
- return interface_data;
-}
-
-} // namespace
-
-// static
-JSObject* MozjsCallbackFunctionInterface::CreateProxy(
- JSContext* context, const scoped_refptr<Wrappable>& wrappable) {
- DCHECK(MozjsGlobalEnvironment::GetFromContext(context));
- JS::RootedObject global_object(
- context,
- MozjsGlobalEnvironment::GetFromContext(context)->global_object());
- DCHECK(global_object);
-
- InterfaceData* interface_data = GetInterfaceData(context);
- JS::RootedObject prototype(context, GetPrototype(context, global_object));
- DCHECK(prototype);
- JS::RootedObject new_object(context, JS_NewObjectWithGivenProto(
- context, &interface_data->instance_class_definition, prototype, NULL));
- DCHECK(new_object);
- JS::RootedObject proxy(context,
- ProxyHandler::NewProxy(context, new_object, prototype, NULL,
- proxy_handler.Pointer()));
- WrapperPrivate::AddPrivateData(context, proxy, wrappable);
- return proxy;
-}
-
-//static
-const JSClass* MozjsCallbackFunctionInterface::PrototypeClass(
- JSContext* context) {
- DCHECK(MozjsGlobalEnvironment::GetFromContext(context));
- JS::RootedObject global_object(
- context,
- MozjsGlobalEnvironment::GetFromContext(context)->global_object());
- DCHECK(global_object);
-
- JS::RootedObject prototype(context, GetPrototype(context, global_object));
- JSClass* proto_class = JS_GetClass(*prototype.address());
- return proto_class;
-}
-
-// static
-JSObject* MozjsCallbackFunctionInterface::GetPrototype(
- JSContext* context, JS::HandleObject global_object) {
- DCHECK(JS_IsGlobalObject(global_object));
-
- InterfaceData* interface_data = GetInterfaceData(context);
- if (!interface_data->prototype) {
- // Create new prototype that has all the props and methods
- InitializePrototypeAndInterfaceObject(
- interface_data, context, global_object);
- }
- DCHECK(interface_data->prototype);
- return interface_data->prototype;
-}
-
-// static
-JSObject* MozjsCallbackFunctionInterface::GetInterfaceObject(
- JSContext* context, JS::HandleObject global_object) {
- DCHECK(JS_IsGlobalObject(global_object));
-
- InterfaceData* interface_data = GetInterfaceData(context);
- if (!interface_data->interface_object) {
- InitializePrototypeAndInterfaceObject(
- interface_data, context, global_object);
- }
- DCHECK(interface_data->interface_object);
- return interface_data->interface_object;
-}
-
-
-namespace {
-} // namespace
-
-
-} // namespace testing
-} // namespace bindings
-} // namespace cobalt
diff --git a/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_callback_function_interface.h b/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_callback_function_interface.h
deleted file mode 100644
index 8a34743..0000000
--- a/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_callback_function_interface.h
+++ /dev/null
@@ -1,52 +0,0 @@
-// Copyright 2017 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/mozjs/templates/interface.h.template
-
-#ifndef MozjsCallbackFunctionInterface_h
-#define MozjsCallbackFunctionInterface_h
-
-#include "base/hash_tables.h"
-#include "base/lazy_instance.h"
-#include "base/memory/ref_counted.h"
-#include "base/threading/thread_checker.h"
-#include "cobalt/base/polymorphic_downcast.h"
-#include "cobalt/script/wrappable.h"
-#include "cobalt/bindings/testing/callback_function_interface.h"
-
-#include "third_party/mozjs/js/src/jsapi.h"
-
-namespace cobalt {
-namespace bindings {
-namespace testing {
-
-class MozjsCallbackFunctionInterface {
- public:
- static JSObject* CreateProxy(JSContext* context,
- const scoped_refptr<script::Wrappable>& wrappable);
- static const JSClass* PrototypeClass(JSContext* context);
- static JSObject* GetPrototype(JSContext* context,
- JS::HandleObject global_object);
- static JSObject* GetInterfaceObject(JSContext* context,
- JS::HandleObject global_object);
-};
-
-} // namespace testing
-} // namespace bindings
-} // namespace cobalt
-
-#endif // MozjsCallbackFunctionInterface_h
diff --git a/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_callback_interface_interface.cc b/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_callback_interface_interface.cc
deleted file mode 100644
index 045f8e2..0000000
--- a/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_callback_interface_interface.cc
+++ /dev/null
@@ -1,585 +0,0 @@
-// Copyright 2017 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/mozjs/templates/interface.cc.template
-
-#include "cobalt/bindings/testing/mozjs_callback_interface_interface.h"
-
-#include "base/debug/trace_event.h"
-#include "cobalt/base/polymorphic_downcast.h"
-#include "cobalt/script/global_environment.h"
-#include "cobalt/script/opaque_handle.h"
-#include "cobalt/script/script_value.h"
-#include "cobalt/bindings/testing/mozjs_single_operation_interface.h"
-#include "cobalt/bindings/testing/single_operation_interface.h"
-
-#include "mozjs_gen_type_conversion.h"
-
-#include "base/lazy_instance.h"
-#include "cobalt/script/exception_state.h"
-#include "cobalt/script/mozjs/callback_function_conversion.h"
-#include "cobalt/script/mozjs/conversion_helpers.h"
-#include "cobalt/script/mozjs/mozjs_callback_function.h"
-#include "cobalt/script/mozjs/mozjs_exception_state.h"
-#include "cobalt/script/mozjs/mozjs_global_environment.h"
-#include "cobalt/script/mozjs/mozjs_object_handle.h"
-#include "cobalt/script/mozjs/mozjs_property_enumerator.h"
-#include "cobalt/script/mozjs/mozjs_user_object_holder.h"
-#include "cobalt/script/mozjs/mozjs_value_handle.h"
-#include "cobalt/script/mozjs/native_promise.h"
-#include "cobalt/script/mozjs/proxy_handler.h"
-#include "cobalt/script/mozjs/type_traits.h"
-#include "cobalt/script/mozjs/wrapper_factory.h"
-#include "cobalt/script/mozjs/wrapper_private.h"
-#include "cobalt/script/property_enumerator.h"
-#include "cobalt/script/sequence.h"
-#include "third_party/mozjs/js/src/jsapi.h"
-#include "third_party/mozjs/js/src/jsfriendapi.h"
-
-namespace {
-using cobalt::bindings::testing::CallbackInterfaceInterface;
-using cobalt::bindings::testing::MozjsCallbackInterfaceInterface;
-using cobalt::bindings::testing::MozjsSingleOperationInterface;
-using cobalt::bindings::testing::SingleOperationInterface;
-using cobalt::script::CallbackInterfaceTraits;
-using cobalt::script::GlobalEnvironment;
-using cobalt::script::OpaqueHandle;
-using cobalt::script::OpaqueHandleHolder;
-using cobalt::script::ScriptValue;
-using cobalt::script::ValueHandle;
-using cobalt::script::Wrappable;
-
-using cobalt::script::CallbackFunction;
-using cobalt::script::CallbackInterfaceTraits;
-using cobalt::script::ExceptionState;
-using cobalt::script::Wrappable;
-using cobalt::script::mozjs::FromJSValue;
-using cobalt::script::mozjs::InterfaceData;
-using cobalt::script::mozjs::MozjsCallbackFunction;
-using cobalt::script::mozjs::MozjsExceptionState;
-using cobalt::script::mozjs::MozjsGlobalEnvironment;
-using cobalt::script::mozjs::MozjsPropertyEnumerator;
-using cobalt::script::mozjs::MozjsUserObjectHolder;
-using cobalt::script::mozjs::ProxyHandler;
-using cobalt::script::mozjs::ToJSValue;
-using cobalt::script::mozjs::TypeTraits;
-using cobalt::script::mozjs::WrapperFactory;
-using cobalt::script::mozjs::WrapperPrivate;
-using cobalt::script::mozjs::kConversionFlagClamped;
-using cobalt::script::mozjs::kConversionFlagNullable;
-using cobalt::script::mozjs::kConversionFlagRestricted;
-using cobalt::script::mozjs::kConversionFlagTreatNullAsEmptyString;
-using cobalt::script::mozjs::kConversionFlagTreatUndefinedAsEmptyString;
-using cobalt::script::mozjs::kNoConversionFlags;
-} // namespace
-
-namespace cobalt {
-namespace bindings {
-namespace testing {
-
-namespace {
-
-class MozjsCallbackInterfaceInterfaceHandler : public ProxyHandler {
- public:
- MozjsCallbackInterfaceInterfaceHandler()
- : ProxyHandler(indexed_property_hooks, named_property_hooks) {}
-
- private:
- static NamedPropertyHooks named_property_hooks;
- static IndexedPropertyHooks indexed_property_hooks;
-};
-
-ProxyHandler::NamedPropertyHooks
-MozjsCallbackInterfaceInterfaceHandler::named_property_hooks = {
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
-};
-ProxyHandler::IndexedPropertyHooks
-MozjsCallbackInterfaceInterfaceHandler::indexed_property_hooks = {
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
-};
-
-static base::LazyInstance<MozjsCallbackInterfaceInterfaceHandler>
- proxy_handler;
-
-JSBool HasInstance(JSContext *context, JS::HandleObject type,
- JS::MutableHandleValue vp, JSBool *success) {
- JS::RootedObject global_object(
- context, JS_GetGlobalForObject(context, type));
- DCHECK(global_object);
-
- JS::RootedObject prototype(
- context, MozjsCallbackInterfaceInterface::GetPrototype(context, global_object));
-
- // |IsDelegate| walks the prototype chain of an object returning true if
- // .prototype is found.
- bool is_delegate;
- if (!IsDelegate(context, prototype, vp, &is_delegate)) {
- *success = false;
- return false;
- }
-
- *success = is_delegate;
- return true;
-}
-
-InterfaceData* CreateCachedInterfaceData() {
- InterfaceData* interface_data = new InterfaceData();
- memset(&interface_data->instance_class_definition, 0,
- sizeof(interface_data->instance_class_definition));
- memset(&interface_data->prototype_class_definition, 0,
- sizeof(interface_data->prototype_class_definition));
- memset(&interface_data->interface_object_class_definition, 0,
- sizeof(interface_data->interface_object_class_definition));
-
- JSClass* instance_class = &interface_data->instance_class_definition;
- const int kGlobalFlags = 0;
- instance_class->name = "CallbackInterfaceInterface";
- instance_class->flags = kGlobalFlags | JSCLASS_HAS_PRIVATE;
- instance_class->addProperty = JS_PropertyStub;
- instance_class->delProperty = JS_DeletePropertyStub;
- instance_class->getProperty = JS_PropertyStub;
- instance_class->setProperty = JS_StrictPropertyStub;
- instance_class->enumerate = JS_EnumerateStub;
- instance_class->resolve = JS_ResolveStub;
- instance_class->convert = JS_ConvertStub;
- // Function to be called before on object of this class is garbage collected.
- instance_class->finalize = &WrapperPrivate::Finalizer;
- // Called to trace objects that can be referenced from this object.
- instance_class->trace = &WrapperPrivate::Trace;
-
- JSClass* prototype_class = &interface_data->prototype_class_definition;
- prototype_class->name = "CallbackInterfaceInterfacePrototype";
- prototype_class->flags = 0;
- prototype_class->addProperty = JS_PropertyStub;
- prototype_class->delProperty = JS_DeletePropertyStub;
- prototype_class->getProperty = JS_PropertyStub;
- prototype_class->setProperty = JS_StrictPropertyStub;
- prototype_class->enumerate = JS_EnumerateStub;
- prototype_class->resolve = JS_ResolveStub;
- prototype_class->convert = JS_ConvertStub;
-
- JSClass* interface_object_class =
- &interface_data->interface_object_class_definition;
- interface_object_class->name = "CallbackInterfaceInterfaceConstructor";
- interface_object_class->flags = 0;
- interface_object_class->addProperty = JS_PropertyStub;
- interface_object_class->delProperty = JS_DeletePropertyStub;
- interface_object_class->getProperty = JS_PropertyStub;
- interface_object_class->setProperty = JS_StrictPropertyStub;
- interface_object_class->enumerate = JS_EnumerateStub;
- interface_object_class->resolve = JS_ResolveStub;
- interface_object_class->convert = JS_ConvertStub;
- interface_object_class->hasInstance = &HasInstance;
- return interface_data;
-}
-
-JSBool get_callbackAttribute(
- JSContext* context, JS::HandleObject object, JS::HandleId id,
- JS::MutableHandleValue vp) {
- const JSClass* proto_class =
- MozjsCallbackInterfaceInterface::PrototypeClass(context);
- if (proto_class == JS_GetClass(object)) {
- // Simply returns true if the object is this class's prototype object.
- // There is no need to return any value due to the object is not a platform
- // object. The execution reaches here when Object.getOwnPropertyDescriptor
- // gets called on native object prototypes.
- return true;
- }
-
- MozjsGlobalEnvironment* global_environment =
- static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context));
- WrapperFactory* wrapper_factory = global_environment->wrapper_factory();
- if (!wrapper_factory->DoesObjectImplementInterface(
- object, base::GetTypeId<CallbackInterfaceInterface>())) {
- MozjsExceptionState exception(context);
- exception.SetSimpleException(script::kDoesNotImplementInterface);
- return false;
- }
- MozjsExceptionState exception_state(context);
- JS::RootedValue result_value(context);
-
- WrapperPrivate* wrapper_private =
- WrapperPrivate::GetFromObject(context, object);
- CallbackInterfaceInterface* impl =
- wrapper_private->wrappable<CallbackInterfaceInterface>().get();
-
- if (!exception_state.is_exception_set()) {
- ToJSValue(context,
- impl->callback_attribute(),
- &result_value);
- }
- if (!exception_state.is_exception_set()) {
- vp.set(result_value);
- }
- return !exception_state.is_exception_set();
-}
-
-JSBool set_callbackAttribute(
- JSContext* context, JS::HandleObject object, JS::HandleId id,
- JSBool strict, JS::MutableHandleValue vp) {
- const JSClass* proto_class =
- MozjsCallbackInterfaceInterface::PrototypeClass(context);
- if (proto_class == JS_GetClass(object)) {
- // Simply returns true if the object is this class's prototype object.
- // There is no need to return any value due to the object is not a platform
- // object. The execution reaches here when Object.getOwnPropertyDescriptor
- // gets called on native object prototypes.
- return true;
- }
-
- MozjsGlobalEnvironment* global_environment =
- static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context));
- WrapperFactory* wrapper_factory = global_environment->wrapper_factory();
- if (!wrapper_factory->DoesObjectImplementInterface(
- object, base::GetTypeId<CallbackInterfaceInterface>())) {
- MozjsExceptionState exception(context);
- exception.SetSimpleException(script::kDoesNotImplementInterface);
- return false;
- }
- MozjsExceptionState exception_state(context);
- JS::RootedValue result_value(context);
-
- WrapperPrivate* wrapper_private =
- WrapperPrivate::GetFromObject(context, object);
- CallbackInterfaceInterface* impl =
- wrapper_private->wrappable<CallbackInterfaceInterface>().get();
- TypeTraits<::cobalt::script::CallbackInterfaceTraits<SingleOperationInterface > >::ConversionType value;
- FromJSValue(context, vp, (kConversionFlagNullable), &exception_state,
- &value);
- if (exception_state.is_exception_set()) {
- return false;
- }
-
- impl->set_callback_attribute(value);
- result_value.set(JS::UndefinedHandleValue);
- return !exception_state.is_exception_set();
-}
-
-JSBool fcn_registerCallback(
- JSContext* context, uint32_t argc, JS::Value *vp) {
- JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
- // Compute the 'this' value.
- JS::RootedValue this_value(context, JS_ComputeThis(context, vp));
- // 'this' should be an object.
- JS::RootedObject object(context);
- if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) {
- return false;
- }
- if (!JS_ValueToObject(context, this_value, object.address())) {
- NOTREACHED();
- return false;
- }
- const JSClass* proto_class =
- MozjsCallbackInterfaceInterface::PrototypeClass(context);
- if (proto_class == JS_GetClass(object)) {
- // Simply returns true if the object is this class's prototype object.
- // There is no need to return any value due to the object is not a platform
- // object. The execution reaches here when Object.getOwnPropertyDescriptor
- // gets called on native object prototypes.
- return true;
- }
-
- MozjsGlobalEnvironment* global_environment =
- static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context));
- WrapperFactory* wrapper_factory = global_environment->wrapper_factory();
- if (!wrapper_factory->DoesObjectImplementInterface(
- object, base::GetTypeId<CallbackInterfaceInterface>())) {
- MozjsExceptionState exception(context);
- exception.SetSimpleException(script::kDoesNotImplementInterface);
- return false;
- }
- MozjsExceptionState exception_state(context);
- JS::RootedValue result_value(context);
-
- WrapperPrivate* wrapper_private =
- WrapperPrivate::GetFromObject(context, object);
- CallbackInterfaceInterface* impl =
- wrapper_private->wrappable<CallbackInterfaceInterface>().get();
- const size_t kMinArguments = 1;
- if (args.length() < kMinArguments) {
- exception_state.SetSimpleException(script::kInvalidNumberOfArguments);
- return false;
- }
- // Non-optional arguments
- TypeTraits<::cobalt::script::CallbackInterfaceTraits<SingleOperationInterface > >::ConversionType callback_interface;
-
- DCHECK_LT(0, args.length());
- JS::RootedValue non_optional_value0(
- context, args[0]);
- FromJSValue(context,
- non_optional_value0,
- kNoConversionFlags,
- &exception_state, &callback_interface);
- if (exception_state.is_exception_set()) {
- return false;
- }
-
- impl->RegisterCallback(callback_interface);
- result_value.set(JS::UndefinedHandleValue);
- return !exception_state.is_exception_set();
-}
-
-JSBool fcn_someOperation(
- JSContext* context, uint32_t argc, JS::Value *vp) {
- JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
- // Compute the 'this' value.
- JS::RootedValue this_value(context, JS_ComputeThis(context, vp));
- // 'this' should be an object.
- JS::RootedObject object(context);
- if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) {
- return false;
- }
- if (!JS_ValueToObject(context, this_value, object.address())) {
- NOTREACHED();
- return false;
- }
- const JSClass* proto_class =
- MozjsCallbackInterfaceInterface::PrototypeClass(context);
- if (proto_class == JS_GetClass(object)) {
- // Simply returns true if the object is this class's prototype object.
- // There is no need to return any value due to the object is not a platform
- // object. The execution reaches here when Object.getOwnPropertyDescriptor
- // gets called on native object prototypes.
- return true;
- }
-
- MozjsGlobalEnvironment* global_environment =
- static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context));
- WrapperFactory* wrapper_factory = global_environment->wrapper_factory();
- if (!wrapper_factory->DoesObjectImplementInterface(
- object, base::GetTypeId<CallbackInterfaceInterface>())) {
- MozjsExceptionState exception(context);
- exception.SetSimpleException(script::kDoesNotImplementInterface);
- return false;
- }
- MozjsExceptionState exception_state(context);
- JS::RootedValue result_value(context);
-
- WrapperPrivate* wrapper_private =
- WrapperPrivate::GetFromObject(context, object);
- CallbackInterfaceInterface* impl =
- wrapper_private->wrappable<CallbackInterfaceInterface>().get();
-
- impl->SomeOperation();
- result_value.set(JS::UndefinedHandleValue);
- return !exception_state.is_exception_set();
-}
-
-
-const JSPropertySpec prototype_properties[] = {
- { // Read/Write property
- "callbackAttribute", 0,
- JSPROP_SHARED | JSPROP_ENUMERATE,
- JSOP_WRAPPER(&get_callbackAttribute),
- JSOP_WRAPPER(&set_callbackAttribute),
- },
- JS_PS_END
-};
-
-const JSFunctionSpec prototype_functions[] = {
- {
- "registerCallback",
- JSOP_WRAPPER(&fcn_registerCallback),
- 1,
- JSPROP_ENUMERATE,
- NULL,
- },
- {
- "someOperation",
- JSOP_WRAPPER(&fcn_someOperation),
- 0,
- JSPROP_ENUMERATE,
- NULL,
- },
- JS_FS_END
-};
-
-const JSPropertySpec interface_object_properties[] = {
- JS_PS_END
-};
-
-const JSFunctionSpec interface_object_functions[] = {
- JS_FS_END
-};
-
-const JSPropertySpec own_properties[] = {
- JS_PS_END
-};
-
-void InitializePrototypeAndInterfaceObject(
- InterfaceData* interface_data, JSContext* context,
- JS::HandleObject global_object) {
- DCHECK(!interface_data->prototype);
- DCHECK(!interface_data->interface_object);
- DCHECK(JS_IsGlobalObject(global_object));
-
- JS::RootedObject parent_prototype(
- context, JS_GetObjectPrototype(context, global_object));
- DCHECK(parent_prototype);
-
- // Create the Prototype object.
- interface_data->prototype = JS_NewObjectWithGivenProto(
- context, &interface_data->prototype_class_definition, parent_prototype,
- NULL);
- bool success = JS_DefineProperties(
- context, interface_data->prototype, prototype_properties);
- DCHECK(success);
- success = JS_DefineFunctions(
- context, interface_data->prototype, prototype_functions);
- DCHECK(success);
-
- JS::RootedObject function_prototype(
- context, JS_GetFunctionPrototype(context, global_object));
- DCHECK(function_prototype);
- // Create the Interface object.
- interface_data->interface_object = JS_NewObjectWithGivenProto(
- context, &interface_data->interface_object_class_definition,
- function_prototype, NULL);
-
- // Add the InterfaceObject.name property.
- JS::RootedObject rooted_interface_object(
- context, interface_data->interface_object);
- JS::RootedValue name_value(context);
- const char name[] =
- "CallbackInterfaceInterface";
- name_value.setString(JS_NewStringCopyZ(context, name));
- success =
- JS_DefineProperty(context, rooted_interface_object, "name", name_value,
- JS_PropertyStub, JS_StrictPropertyStub,
- JSPROP_READONLY);
- DCHECK(success);
-
- // Define interface object properties (including constants).
- success = JS_DefineProperties(context, rooted_interface_object,
- interface_object_properties);
- DCHECK(success);
- // Define interface object functions (static).
- success = JS_DefineFunctions(context, rooted_interface_object,
- interface_object_functions);
- DCHECK(success);
-
-
- // Set the Prototype.constructor and Constructor.prototype properties.
- DCHECK(interface_data->interface_object);
- DCHECK(interface_data->prototype);
- JS::RootedObject rooted_prototype(context, interface_data->prototype);
- success = JS_LinkConstructorAndPrototype(
- context,
- rooted_interface_object,
- rooted_prototype);
- DCHECK(success);
-}
-
-InterfaceData* GetInterfaceData(JSContext* context) {
- MozjsGlobalEnvironment* global_environment =
- static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context));
- // Use the address of the properties definition for this interface as a
- // unique key for looking up the InterfaceData for this interface.
- intptr_t key = reinterpret_cast<intptr_t>(&own_properties);
- InterfaceData* interface_data = global_environment->GetInterfaceData(key);
- if (!interface_data) {
- interface_data = CreateCachedInterfaceData();
- DCHECK(interface_data);
- global_environment->CacheInterfaceData(key, interface_data);
- DCHECK_EQ(interface_data, global_environment->GetInterfaceData(key));
- }
- return interface_data;
-}
-
-} // namespace
-
-// static
-JSObject* MozjsCallbackInterfaceInterface::CreateProxy(
- JSContext* context, const scoped_refptr<Wrappable>& wrappable) {
- DCHECK(MozjsGlobalEnvironment::GetFromContext(context));
- JS::RootedObject global_object(
- context,
- MozjsGlobalEnvironment::GetFromContext(context)->global_object());
- DCHECK(global_object);
-
- InterfaceData* interface_data = GetInterfaceData(context);
- JS::RootedObject prototype(context, GetPrototype(context, global_object));
- DCHECK(prototype);
- JS::RootedObject new_object(context, JS_NewObjectWithGivenProto(
- context, &interface_data->instance_class_definition, prototype, NULL));
- DCHECK(new_object);
- JS::RootedObject proxy(context,
- ProxyHandler::NewProxy(context, new_object, prototype, NULL,
- proxy_handler.Pointer()));
- WrapperPrivate::AddPrivateData(context, proxy, wrappable);
- return proxy;
-}
-
-//static
-const JSClass* MozjsCallbackInterfaceInterface::PrototypeClass(
- JSContext* context) {
- DCHECK(MozjsGlobalEnvironment::GetFromContext(context));
- JS::RootedObject global_object(
- context,
- MozjsGlobalEnvironment::GetFromContext(context)->global_object());
- DCHECK(global_object);
-
- JS::RootedObject prototype(context, GetPrototype(context, global_object));
- JSClass* proto_class = JS_GetClass(*prototype.address());
- return proto_class;
-}
-
-// static
-JSObject* MozjsCallbackInterfaceInterface::GetPrototype(
- JSContext* context, JS::HandleObject global_object) {
- DCHECK(JS_IsGlobalObject(global_object));
-
- InterfaceData* interface_data = GetInterfaceData(context);
- if (!interface_data->prototype) {
- // Create new prototype that has all the props and methods
- InitializePrototypeAndInterfaceObject(
- interface_data, context, global_object);
- }
- DCHECK(interface_data->prototype);
- return interface_data->prototype;
-}
-
-// static
-JSObject* MozjsCallbackInterfaceInterface::GetInterfaceObject(
- JSContext* context, JS::HandleObject global_object) {
- DCHECK(JS_IsGlobalObject(global_object));
-
- InterfaceData* interface_data = GetInterfaceData(context);
- if (!interface_data->interface_object) {
- InitializePrototypeAndInterfaceObject(
- interface_data, context, global_object);
- }
- DCHECK(interface_data->interface_object);
- return interface_data->interface_object;
-}
-
-
-namespace {
-} // namespace
-
-
-} // namespace testing
-} // namespace bindings
-} // namespace cobalt
diff --git a/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_callback_interface_interface.h b/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_callback_interface_interface.h
deleted file mode 100644
index 98a8b45..0000000
--- a/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_callback_interface_interface.h
+++ /dev/null
@@ -1,52 +0,0 @@
-// Copyright 2017 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/mozjs/templates/interface.h.template
-
-#ifndef MozjsCallbackInterfaceInterface_h
-#define MozjsCallbackInterfaceInterface_h
-
-#include "base/hash_tables.h"
-#include "base/lazy_instance.h"
-#include "base/memory/ref_counted.h"
-#include "base/threading/thread_checker.h"
-#include "cobalt/base/polymorphic_downcast.h"
-#include "cobalt/script/wrappable.h"
-#include "cobalt/bindings/testing/callback_interface_interface.h"
-
-#include "third_party/mozjs/js/src/jsapi.h"
-
-namespace cobalt {
-namespace bindings {
-namespace testing {
-
-class MozjsCallbackInterfaceInterface {
- public:
- static JSObject* CreateProxy(JSContext* context,
- const scoped_refptr<script::Wrappable>& wrappable);
- static const JSClass* PrototypeClass(JSContext* context);
- static JSObject* GetPrototype(JSContext* context,
- JS::HandleObject global_object);
- static JSObject* GetInterfaceObject(JSContext* context,
- JS::HandleObject global_object);
-};
-
-} // namespace testing
-} // namespace bindings
-} // namespace cobalt
-
-#endif // MozjsCallbackInterfaceInterface_h
diff --git a/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_conditional_interface.cc b/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_conditional_interface.cc
deleted file mode 100644
index fc0d3f4..0000000
--- a/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_conditional_interface.cc
+++ /dev/null
@@ -1,670 +0,0 @@
-// Copyright 2017 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/mozjs/templates/interface.cc.template
-
-#if defined(ENABLE_CONDITIONAL_INTERFACE)
-
-#include "cobalt/bindings/testing/mozjs_conditional_interface.h"
-
-#include "base/debug/trace_event.h"
-#include "cobalt/base/polymorphic_downcast.h"
-#include "cobalt/script/global_environment.h"
-#include "cobalt/script/opaque_handle.h"
-#include "cobalt/script/script_value.h"
-
-#include "mozjs_gen_type_conversion.h"
-
-#include "base/lazy_instance.h"
-#include "cobalt/script/exception_state.h"
-#include "cobalt/script/mozjs/callback_function_conversion.h"
-#include "cobalt/script/mozjs/conversion_helpers.h"
-#include "cobalt/script/mozjs/mozjs_callback_function.h"
-#include "cobalt/script/mozjs/mozjs_exception_state.h"
-#include "cobalt/script/mozjs/mozjs_global_environment.h"
-#include "cobalt/script/mozjs/mozjs_object_handle.h"
-#include "cobalt/script/mozjs/mozjs_property_enumerator.h"
-#include "cobalt/script/mozjs/mozjs_user_object_holder.h"
-#include "cobalt/script/mozjs/mozjs_value_handle.h"
-#include "cobalt/script/mozjs/native_promise.h"
-#include "cobalt/script/mozjs/proxy_handler.h"
-#include "cobalt/script/mozjs/type_traits.h"
-#include "cobalt/script/mozjs/wrapper_factory.h"
-#include "cobalt/script/mozjs/wrapper_private.h"
-#include "cobalt/script/property_enumerator.h"
-#include "cobalt/script/sequence.h"
-#include "third_party/mozjs/js/src/jsapi.h"
-#include "third_party/mozjs/js/src/jsfriendapi.h"
-
-namespace {
-using cobalt::bindings::testing::ConditionalInterface;
-using cobalt::bindings::testing::MozjsConditionalInterface;
-using cobalt::script::CallbackInterfaceTraits;
-using cobalt::script::GlobalEnvironment;
-using cobalt::script::OpaqueHandle;
-using cobalt::script::OpaqueHandleHolder;
-using cobalt::script::ScriptValue;
-using cobalt::script::ValueHandle;
-using cobalt::script::Wrappable;
-
-using cobalt::script::CallbackFunction;
-using cobalt::script::CallbackInterfaceTraits;
-using cobalt::script::ExceptionState;
-using cobalt::script::Wrappable;
-using cobalt::script::mozjs::FromJSValue;
-using cobalt::script::mozjs::InterfaceData;
-using cobalt::script::mozjs::MozjsCallbackFunction;
-using cobalt::script::mozjs::MozjsExceptionState;
-using cobalt::script::mozjs::MozjsGlobalEnvironment;
-using cobalt::script::mozjs::MozjsPropertyEnumerator;
-using cobalt::script::mozjs::MozjsUserObjectHolder;
-using cobalt::script::mozjs::ProxyHandler;
-using cobalt::script::mozjs::ToJSValue;
-using cobalt::script::mozjs::TypeTraits;
-using cobalt::script::mozjs::WrapperFactory;
-using cobalt::script::mozjs::WrapperPrivate;
-using cobalt::script::mozjs::kConversionFlagClamped;
-using cobalt::script::mozjs::kConversionFlagNullable;
-using cobalt::script::mozjs::kConversionFlagRestricted;
-using cobalt::script::mozjs::kConversionFlagTreatNullAsEmptyString;
-using cobalt::script::mozjs::kConversionFlagTreatUndefinedAsEmptyString;
-using cobalt::script::mozjs::kNoConversionFlags;
-} // namespace
-
-namespace cobalt {
-namespace bindings {
-namespace testing {
-
-namespace {
-
-class MozjsConditionalInterfaceHandler : public ProxyHandler {
- public:
- MozjsConditionalInterfaceHandler()
- : ProxyHandler(indexed_property_hooks, named_property_hooks) {}
-
- private:
- static NamedPropertyHooks named_property_hooks;
- static IndexedPropertyHooks indexed_property_hooks;
-};
-
-ProxyHandler::NamedPropertyHooks
-MozjsConditionalInterfaceHandler::named_property_hooks = {
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
-};
-ProxyHandler::IndexedPropertyHooks
-MozjsConditionalInterfaceHandler::indexed_property_hooks = {
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
-};
-
-static base::LazyInstance<MozjsConditionalInterfaceHandler>
- proxy_handler;
-
-JSBool HasInstance(JSContext *context, JS::HandleObject type,
- JS::MutableHandleValue vp, JSBool *success) {
- JS::RootedObject global_object(
- context, JS_GetGlobalForObject(context, type));
- DCHECK(global_object);
-
- JS::RootedObject prototype(
- context, MozjsConditionalInterface::GetPrototype(context, global_object));
-
- // |IsDelegate| walks the prototype chain of an object returning true if
- // .prototype is found.
- bool is_delegate;
- if (!IsDelegate(context, prototype, vp, &is_delegate)) {
- *success = false;
- return false;
- }
-
- *success = is_delegate;
- return true;
-}
-
-InterfaceData* CreateCachedInterfaceData() {
- InterfaceData* interface_data = new InterfaceData();
- memset(&interface_data->instance_class_definition, 0,
- sizeof(interface_data->instance_class_definition));
- memset(&interface_data->prototype_class_definition, 0,
- sizeof(interface_data->prototype_class_definition));
- memset(&interface_data->interface_object_class_definition, 0,
- sizeof(interface_data->interface_object_class_definition));
-
- JSClass* instance_class = &interface_data->instance_class_definition;
- const int kGlobalFlags = 0;
- instance_class->name = "ConditionalInterface";
- instance_class->flags = kGlobalFlags | JSCLASS_HAS_PRIVATE;
- instance_class->addProperty = JS_PropertyStub;
- instance_class->delProperty = JS_DeletePropertyStub;
- instance_class->getProperty = JS_PropertyStub;
- instance_class->setProperty = JS_StrictPropertyStub;
- instance_class->enumerate = JS_EnumerateStub;
- instance_class->resolve = JS_ResolveStub;
- instance_class->convert = JS_ConvertStub;
- // Function to be called before on object of this class is garbage collected.
- instance_class->finalize = &WrapperPrivate::Finalizer;
- // Called to trace objects that can be referenced from this object.
- instance_class->trace = &WrapperPrivate::Trace;
-
- JSClass* prototype_class = &interface_data->prototype_class_definition;
- prototype_class->name = "ConditionalInterfacePrototype";
- prototype_class->flags = 0;
- prototype_class->addProperty = JS_PropertyStub;
- prototype_class->delProperty = JS_DeletePropertyStub;
- prototype_class->getProperty = JS_PropertyStub;
- prototype_class->setProperty = JS_StrictPropertyStub;
- prototype_class->enumerate = JS_EnumerateStub;
- prototype_class->resolve = JS_ResolveStub;
- prototype_class->convert = JS_ConvertStub;
-
- JSClass* interface_object_class =
- &interface_data->interface_object_class_definition;
- interface_object_class->name = "ConditionalInterfaceConstructor";
- interface_object_class->flags = 0;
- interface_object_class->addProperty = JS_PropertyStub;
- interface_object_class->delProperty = JS_DeletePropertyStub;
- interface_object_class->getProperty = JS_PropertyStub;
- interface_object_class->setProperty = JS_StrictPropertyStub;
- interface_object_class->enumerate = JS_EnumerateStub;
- interface_object_class->resolve = JS_ResolveStub;
- interface_object_class->convert = JS_ConvertStub;
- interface_object_class->hasInstance = &HasInstance;
- return interface_data;
-}
-
-#if defined(ENABLE_CONDITIONAL_PROPERTY)
-JSBool get_enabledAttribute(
- JSContext* context, JS::HandleObject object, JS::HandleId id,
- JS::MutableHandleValue vp) {
- const JSClass* proto_class =
- MozjsConditionalInterface::PrototypeClass(context);
- if (proto_class == JS_GetClass(object)) {
- // Simply returns true if the object is this class's prototype object.
- // There is no need to return any value due to the object is not a platform
- // object. The execution reaches here when Object.getOwnPropertyDescriptor
- // gets called on native object prototypes.
- return true;
- }
-
- MozjsGlobalEnvironment* global_environment =
- static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context));
- WrapperFactory* wrapper_factory = global_environment->wrapper_factory();
- if (!wrapper_factory->DoesObjectImplementInterface(
- object, base::GetTypeId<ConditionalInterface>())) {
- MozjsExceptionState exception(context);
- exception.SetSimpleException(script::kDoesNotImplementInterface);
- return false;
- }
- MozjsExceptionState exception_state(context);
- JS::RootedValue result_value(context);
-
- WrapperPrivate* wrapper_private =
- WrapperPrivate::GetFromObject(context, object);
- ConditionalInterface* impl =
- wrapper_private->wrappable<ConditionalInterface>().get();
-
- if (!exception_state.is_exception_set()) {
- ToJSValue(context,
- impl->enabled_attribute(),
- &result_value);
- }
- if (!exception_state.is_exception_set()) {
- vp.set(result_value);
- }
- return !exception_state.is_exception_set();
-}
-
-JSBool set_enabledAttribute(
- JSContext* context, JS::HandleObject object, JS::HandleId id,
- JSBool strict, JS::MutableHandleValue vp) {
- const JSClass* proto_class =
- MozjsConditionalInterface::PrototypeClass(context);
- if (proto_class == JS_GetClass(object)) {
- // Simply returns true if the object is this class's prototype object.
- // There is no need to return any value due to the object is not a platform
- // object. The execution reaches here when Object.getOwnPropertyDescriptor
- // gets called on native object prototypes.
- return true;
- }
-
- MozjsGlobalEnvironment* global_environment =
- static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context));
- WrapperFactory* wrapper_factory = global_environment->wrapper_factory();
- if (!wrapper_factory->DoesObjectImplementInterface(
- object, base::GetTypeId<ConditionalInterface>())) {
- MozjsExceptionState exception(context);
- exception.SetSimpleException(script::kDoesNotImplementInterface);
- return false;
- }
- MozjsExceptionState exception_state(context);
- JS::RootedValue result_value(context);
-
- WrapperPrivate* wrapper_private =
- WrapperPrivate::GetFromObject(context, object);
- ConditionalInterface* impl =
- wrapper_private->wrappable<ConditionalInterface>().get();
- TypeTraits<int32_t >::ConversionType value;
- FromJSValue(context, vp, kNoConversionFlags, &exception_state,
- &value);
- if (exception_state.is_exception_set()) {
- return false;
- }
-
- impl->set_enabled_attribute(value);
- result_value.set(JS::UndefinedHandleValue);
- return !exception_state.is_exception_set();
-}
-
-#endif // ENABLE_CONDITIONAL_PROPERTY
-#if defined(NO_ENABLE_CONDITIONAL_PROPERTY)
-JSBool get_disabledAttribute(
- JSContext* context, JS::HandleObject object, JS::HandleId id,
- JS::MutableHandleValue vp) {
- const JSClass* proto_class =
- MozjsConditionalInterface::PrototypeClass(context);
- if (proto_class == JS_GetClass(object)) {
- // Simply returns true if the object is this class's prototype object.
- // There is no need to return any value due to the object is not a platform
- // object. The execution reaches here when Object.getOwnPropertyDescriptor
- // gets called on native object prototypes.
- return true;
- }
-
- MozjsGlobalEnvironment* global_environment =
- static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context));
- WrapperFactory* wrapper_factory = global_environment->wrapper_factory();
- if (!wrapper_factory->DoesObjectImplementInterface(
- object, base::GetTypeId<ConditionalInterface>())) {
- MozjsExceptionState exception(context);
- exception.SetSimpleException(script::kDoesNotImplementInterface);
- return false;
- }
- MozjsExceptionState exception_state(context);
- JS::RootedValue result_value(context);
-
- WrapperPrivate* wrapper_private =
- WrapperPrivate::GetFromObject(context, object);
- ConditionalInterface* impl =
- wrapper_private->wrappable<ConditionalInterface>().get();
-
- if (!exception_state.is_exception_set()) {
- ToJSValue(context,
- impl->disabled_attribute(),
- &result_value);
- }
- if (!exception_state.is_exception_set()) {
- vp.set(result_value);
- }
- return !exception_state.is_exception_set();
-}
-
-JSBool set_disabledAttribute(
- JSContext* context, JS::HandleObject object, JS::HandleId id,
- JSBool strict, JS::MutableHandleValue vp) {
- const JSClass* proto_class =
- MozjsConditionalInterface::PrototypeClass(context);
- if (proto_class == JS_GetClass(object)) {
- // Simply returns true if the object is this class's prototype object.
- // There is no need to return any value due to the object is not a platform
- // object. The execution reaches here when Object.getOwnPropertyDescriptor
- // gets called on native object prototypes.
- return true;
- }
-
- MozjsGlobalEnvironment* global_environment =
- static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context));
- WrapperFactory* wrapper_factory = global_environment->wrapper_factory();
- if (!wrapper_factory->DoesObjectImplementInterface(
- object, base::GetTypeId<ConditionalInterface>())) {
- MozjsExceptionState exception(context);
- exception.SetSimpleException(script::kDoesNotImplementInterface);
- return false;
- }
- MozjsExceptionState exception_state(context);
- JS::RootedValue result_value(context);
-
- WrapperPrivate* wrapper_private =
- WrapperPrivate::GetFromObject(context, object);
- ConditionalInterface* impl =
- wrapper_private->wrappable<ConditionalInterface>().get();
- TypeTraits<int32_t >::ConversionType value;
- FromJSValue(context, vp, kNoConversionFlags, &exception_state,
- &value);
- if (exception_state.is_exception_set()) {
- return false;
- }
-
- impl->set_disabled_attribute(value);
- result_value.set(JS::UndefinedHandleValue);
- return !exception_state.is_exception_set();
-}
-
-#endif // NO_ENABLE_CONDITIONAL_PROPERTY
-#if defined(NO_ENABLE_CONDITIONAL_PROPERTY)
-JSBool fcn_disabledOperation(
- JSContext* context, uint32_t argc, JS::Value *vp) {
- JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
- // Compute the 'this' value.
- JS::RootedValue this_value(context, JS_ComputeThis(context, vp));
- // 'this' should be an object.
- JS::RootedObject object(context);
- if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) {
- return false;
- }
- if (!JS_ValueToObject(context, this_value, object.address())) {
- NOTREACHED();
- return false;
- }
- const JSClass* proto_class =
- MozjsConditionalInterface::PrototypeClass(context);
- if (proto_class == JS_GetClass(object)) {
- // Simply returns true if the object is this class's prototype object.
- // There is no need to return any value due to the object is not a platform
- // object. The execution reaches here when Object.getOwnPropertyDescriptor
- // gets called on native object prototypes.
- return true;
- }
-
- MozjsGlobalEnvironment* global_environment =
- static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context));
- WrapperFactory* wrapper_factory = global_environment->wrapper_factory();
- if (!wrapper_factory->DoesObjectImplementInterface(
- object, base::GetTypeId<ConditionalInterface>())) {
- MozjsExceptionState exception(context);
- exception.SetSimpleException(script::kDoesNotImplementInterface);
- return false;
- }
- MozjsExceptionState exception_state(context);
- JS::RootedValue result_value(context);
-
- WrapperPrivate* wrapper_private =
- WrapperPrivate::GetFromObject(context, object);
- ConditionalInterface* impl =
- wrapper_private->wrappable<ConditionalInterface>().get();
-
- impl->DisabledOperation();
- result_value.set(JS::UndefinedHandleValue);
- return !exception_state.is_exception_set();
-}
-
-#endif // NO_ENABLE_CONDITIONAL_PROPERTY
-#if defined(ENABLE_CONDITIONAL_PROPERTY)
-JSBool fcn_enabledOperation(
- JSContext* context, uint32_t argc, JS::Value *vp) {
- JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
- // Compute the 'this' value.
- JS::RootedValue this_value(context, JS_ComputeThis(context, vp));
- // 'this' should be an object.
- JS::RootedObject object(context);
- if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) {
- return false;
- }
- if (!JS_ValueToObject(context, this_value, object.address())) {
- NOTREACHED();
- return false;
- }
- const JSClass* proto_class =
- MozjsConditionalInterface::PrototypeClass(context);
- if (proto_class == JS_GetClass(object)) {
- // Simply returns true if the object is this class's prototype object.
- // There is no need to return any value due to the object is not a platform
- // object. The execution reaches here when Object.getOwnPropertyDescriptor
- // gets called on native object prototypes.
- return true;
- }
-
- MozjsGlobalEnvironment* global_environment =
- static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context));
- WrapperFactory* wrapper_factory = global_environment->wrapper_factory();
- if (!wrapper_factory->DoesObjectImplementInterface(
- object, base::GetTypeId<ConditionalInterface>())) {
- MozjsExceptionState exception(context);
- exception.SetSimpleException(script::kDoesNotImplementInterface);
- return false;
- }
- MozjsExceptionState exception_state(context);
- JS::RootedValue result_value(context);
-
- WrapperPrivate* wrapper_private =
- WrapperPrivate::GetFromObject(context, object);
- ConditionalInterface* impl =
- wrapper_private->wrappable<ConditionalInterface>().get();
-
- impl->EnabledOperation();
- result_value.set(JS::UndefinedHandleValue);
- return !exception_state.is_exception_set();
-}
-
-#endif // ENABLE_CONDITIONAL_PROPERTY
-
-const JSPropertySpec prototype_properties[] = {
-#if defined(ENABLE_CONDITIONAL_PROPERTY)
- { // Read/Write property
- "enabledAttribute", 0,
- JSPROP_SHARED | JSPROP_ENUMERATE,
- JSOP_WRAPPER(&get_enabledAttribute),
- JSOP_WRAPPER(&set_enabledAttribute),
- },
-#endif // ENABLE_CONDITIONAL_PROPERTY
-#if defined(NO_ENABLE_CONDITIONAL_PROPERTY)
- { // Read/Write property
- "disabledAttribute", 0,
- JSPROP_SHARED | JSPROP_ENUMERATE,
- JSOP_WRAPPER(&get_disabledAttribute),
- JSOP_WRAPPER(&set_disabledAttribute),
- },
-#endif // NO_ENABLE_CONDITIONAL_PROPERTY
- JS_PS_END
-};
-
-const JSFunctionSpec prototype_functions[] = {
-#if defined(NO_ENABLE_CONDITIONAL_PROPERTY)
- {
- "disabledOperation",
- JSOP_WRAPPER(&fcn_disabledOperation),
- 0,
- JSPROP_ENUMERATE,
- NULL,
- },
-#endif // NO_ENABLE_CONDITIONAL_PROPERTY
-#if defined(ENABLE_CONDITIONAL_PROPERTY)
- {
- "enabledOperation",
- JSOP_WRAPPER(&fcn_enabledOperation),
- 0,
- JSPROP_ENUMERATE,
- NULL,
- },
-#endif // ENABLE_CONDITIONAL_PROPERTY
- JS_FS_END
-};
-
-const JSPropertySpec interface_object_properties[] = {
- JS_PS_END
-};
-
-const JSFunctionSpec interface_object_functions[] = {
- JS_FS_END
-};
-
-const JSPropertySpec own_properties[] = {
- JS_PS_END
-};
-
-void InitializePrototypeAndInterfaceObject(
- InterfaceData* interface_data, JSContext* context,
- JS::HandleObject global_object) {
- DCHECK(!interface_data->prototype);
- DCHECK(!interface_data->interface_object);
- DCHECK(JS_IsGlobalObject(global_object));
-
- JS::RootedObject parent_prototype(
- context, JS_GetObjectPrototype(context, global_object));
- DCHECK(parent_prototype);
-
- // Create the Prototype object.
- interface_data->prototype = JS_NewObjectWithGivenProto(
- context, &interface_data->prototype_class_definition, parent_prototype,
- NULL);
- bool success = JS_DefineProperties(
- context, interface_data->prototype, prototype_properties);
- DCHECK(success);
- success = JS_DefineFunctions(
- context, interface_data->prototype, prototype_functions);
- DCHECK(success);
-
- JS::RootedObject function_prototype(
- context, JS_GetFunctionPrototype(context, global_object));
- DCHECK(function_prototype);
- // Create the Interface object.
- interface_data->interface_object = JS_NewObjectWithGivenProto(
- context, &interface_data->interface_object_class_definition,
- function_prototype, NULL);
-
- // Add the InterfaceObject.name property.
- JS::RootedObject rooted_interface_object(
- context, interface_data->interface_object);
- JS::RootedValue name_value(context);
- const char name[] =
- "ConditionalInterface";
- name_value.setString(JS_NewStringCopyZ(context, name));
- success =
- JS_DefineProperty(context, rooted_interface_object, "name", name_value,
- JS_PropertyStub, JS_StrictPropertyStub,
- JSPROP_READONLY);
- DCHECK(success);
-
- // Define interface object properties (including constants).
- success = JS_DefineProperties(context, rooted_interface_object,
- interface_object_properties);
- DCHECK(success);
- // Define interface object functions (static).
- success = JS_DefineFunctions(context, rooted_interface_object,
- interface_object_functions);
- DCHECK(success);
-
-
- // Set the Prototype.constructor and Constructor.prototype properties.
- DCHECK(interface_data->interface_object);
- DCHECK(interface_data->prototype);
- JS::RootedObject rooted_prototype(context, interface_data->prototype);
- success = JS_LinkConstructorAndPrototype(
- context,
- rooted_interface_object,
- rooted_prototype);
- DCHECK(success);
-}
-
-InterfaceData* GetInterfaceData(JSContext* context) {
- MozjsGlobalEnvironment* global_environment =
- static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context));
- // Use the address of the properties definition for this interface as a
- // unique key for looking up the InterfaceData for this interface.
- intptr_t key = reinterpret_cast<intptr_t>(&own_properties);
- InterfaceData* interface_data = global_environment->GetInterfaceData(key);
- if (!interface_data) {
- interface_data = CreateCachedInterfaceData();
- DCHECK(interface_data);
- global_environment->CacheInterfaceData(key, interface_data);
- DCHECK_EQ(interface_data, global_environment->GetInterfaceData(key));
- }
- return interface_data;
-}
-
-} // namespace
-
-// static
-JSObject* MozjsConditionalInterface::CreateProxy(
- JSContext* context, const scoped_refptr<Wrappable>& wrappable) {
- DCHECK(MozjsGlobalEnvironment::GetFromContext(context));
- JS::RootedObject global_object(
- context,
- MozjsGlobalEnvironment::GetFromContext(context)->global_object());
- DCHECK(global_object);
-
- InterfaceData* interface_data = GetInterfaceData(context);
- JS::RootedObject prototype(context, GetPrototype(context, global_object));
- DCHECK(prototype);
- JS::RootedObject new_object(context, JS_NewObjectWithGivenProto(
- context, &interface_data->instance_class_definition, prototype, NULL));
- DCHECK(new_object);
- JS::RootedObject proxy(context,
- ProxyHandler::NewProxy(context, new_object, prototype, NULL,
- proxy_handler.Pointer()));
- WrapperPrivate::AddPrivateData(context, proxy, wrappable);
- return proxy;
-}
-
-//static
-const JSClass* MozjsConditionalInterface::PrototypeClass(
- JSContext* context) {
- DCHECK(MozjsGlobalEnvironment::GetFromContext(context));
- JS::RootedObject global_object(
- context,
- MozjsGlobalEnvironment::GetFromContext(context)->global_object());
- DCHECK(global_object);
-
- JS::RootedObject prototype(context, GetPrototype(context, global_object));
- JSClass* proto_class = JS_GetClass(*prototype.address());
- return proto_class;
-}
-
-// static
-JSObject* MozjsConditionalInterface::GetPrototype(
- JSContext* context, JS::HandleObject global_object) {
- DCHECK(JS_IsGlobalObject(global_object));
-
- InterfaceData* interface_data = GetInterfaceData(context);
- if (!interface_data->prototype) {
- // Create new prototype that has all the props and methods
- InitializePrototypeAndInterfaceObject(
- interface_data, context, global_object);
- }
- DCHECK(interface_data->prototype);
- return interface_data->prototype;
-}
-
-// static
-JSObject* MozjsConditionalInterface::GetInterfaceObject(
- JSContext* context, JS::HandleObject global_object) {
- DCHECK(JS_IsGlobalObject(global_object));
-
- InterfaceData* interface_data = GetInterfaceData(context);
- if (!interface_data->interface_object) {
- InitializePrototypeAndInterfaceObject(
- interface_data, context, global_object);
- }
- DCHECK(interface_data->interface_object);
- return interface_data->interface_object;
-}
-
-
-namespace {
-} // namespace
-
-
-} // namespace testing
-} // namespace bindings
-} // namespace cobalt
-#endif // defined(ENABLE_CONDITIONAL_INTERFACE)
diff --git a/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_conditional_interface.h b/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_conditional_interface.h
deleted file mode 100644
index fd13293..0000000
--- a/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_conditional_interface.h
+++ /dev/null
@@ -1,56 +0,0 @@
-// Copyright 2017 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/mozjs/templates/interface.h.template
-
-#ifndef MozjsConditionalInterface_h
-#define MozjsConditionalInterface_h
-
-#if defined(ENABLE_CONDITIONAL_INTERFACE)
-
-#include "base/hash_tables.h"
-#include "base/lazy_instance.h"
-#include "base/memory/ref_counted.h"
-#include "base/threading/thread_checker.h"
-#include "cobalt/base/polymorphic_downcast.h"
-#include "cobalt/script/wrappable.h"
-#include "cobalt/bindings/testing/conditional_interface.h"
-
-#include "third_party/mozjs/js/src/jsapi.h"
-
-namespace cobalt {
-namespace bindings {
-namespace testing {
-
-class MozjsConditionalInterface {
- public:
- static JSObject* CreateProxy(JSContext* context,
- const scoped_refptr<script::Wrappable>& wrappable);
- static const JSClass* PrototypeClass(JSContext* context);
- static JSObject* GetPrototype(JSContext* context,
- JS::HandleObject global_object);
- static JSObject* GetInterfaceObject(JSContext* context,
- JS::HandleObject global_object);
-};
-
-} // namespace testing
-} // namespace bindings
-} // namespace cobalt
-
-#endif // defined(ENABLE_CONDITIONAL_INTERFACE)
-
-#endif // MozjsConditionalInterface_h
diff --git a/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_constants_interface.cc b/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_constants_interface.cc
deleted file mode 100644
index 589bf2c..0000000
--- a/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_constants_interface.cc
+++ /dev/null
@@ -1,422 +0,0 @@
-// Copyright 2017 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/mozjs/templates/interface.cc.template
-
-#include "cobalt/bindings/testing/mozjs_constants_interface.h"
-
-#include "base/debug/trace_event.h"
-#include "cobalt/base/polymorphic_downcast.h"
-#include "cobalt/script/global_environment.h"
-#include "cobalt/script/opaque_handle.h"
-#include "cobalt/script/script_value.h"
-
-#include "mozjs_gen_type_conversion.h"
-
-#include "base/lazy_instance.h"
-#include "cobalt/script/exception_state.h"
-#include "cobalt/script/mozjs/callback_function_conversion.h"
-#include "cobalt/script/mozjs/conversion_helpers.h"
-#include "cobalt/script/mozjs/mozjs_callback_function.h"
-#include "cobalt/script/mozjs/mozjs_exception_state.h"
-#include "cobalt/script/mozjs/mozjs_global_environment.h"
-#include "cobalt/script/mozjs/mozjs_object_handle.h"
-#include "cobalt/script/mozjs/mozjs_property_enumerator.h"
-#include "cobalt/script/mozjs/mozjs_user_object_holder.h"
-#include "cobalt/script/mozjs/mozjs_value_handle.h"
-#include "cobalt/script/mozjs/native_promise.h"
-#include "cobalt/script/mozjs/proxy_handler.h"
-#include "cobalt/script/mozjs/type_traits.h"
-#include "cobalt/script/mozjs/wrapper_factory.h"
-#include "cobalt/script/mozjs/wrapper_private.h"
-#include "cobalt/script/property_enumerator.h"
-#include "cobalt/script/sequence.h"
-#include "third_party/mozjs/js/src/jsapi.h"
-#include "third_party/mozjs/js/src/jsfriendapi.h"
-
-namespace {
-using cobalt::bindings::testing::ConstantsInterface;
-using cobalt::bindings::testing::MozjsConstantsInterface;
-using cobalt::script::CallbackInterfaceTraits;
-using cobalt::script::GlobalEnvironment;
-using cobalt::script::OpaqueHandle;
-using cobalt::script::OpaqueHandleHolder;
-using cobalt::script::ScriptValue;
-using cobalt::script::ValueHandle;
-using cobalt::script::Wrappable;
-
-using cobalt::script::CallbackFunction;
-using cobalt::script::CallbackInterfaceTraits;
-using cobalt::script::ExceptionState;
-using cobalt::script::Wrappable;
-using cobalt::script::mozjs::FromJSValue;
-using cobalt::script::mozjs::InterfaceData;
-using cobalt::script::mozjs::MozjsCallbackFunction;
-using cobalt::script::mozjs::MozjsExceptionState;
-using cobalt::script::mozjs::MozjsGlobalEnvironment;
-using cobalt::script::mozjs::MozjsPropertyEnumerator;
-using cobalt::script::mozjs::MozjsUserObjectHolder;
-using cobalt::script::mozjs::ProxyHandler;
-using cobalt::script::mozjs::ToJSValue;
-using cobalt::script::mozjs::TypeTraits;
-using cobalt::script::mozjs::WrapperFactory;
-using cobalt::script::mozjs::WrapperPrivate;
-using cobalt::script::mozjs::kConversionFlagClamped;
-using cobalt::script::mozjs::kConversionFlagNullable;
-using cobalt::script::mozjs::kConversionFlagRestricted;
-using cobalt::script::mozjs::kConversionFlagTreatNullAsEmptyString;
-using cobalt::script::mozjs::kConversionFlagTreatUndefinedAsEmptyString;
-using cobalt::script::mozjs::kNoConversionFlags;
-} // namespace
-
-namespace cobalt {
-namespace bindings {
-namespace testing {
-
-namespace {
-
-class MozjsConstantsInterfaceHandler : public ProxyHandler {
- public:
- MozjsConstantsInterfaceHandler()
- : ProxyHandler(indexed_property_hooks, named_property_hooks) {}
-
- private:
- static NamedPropertyHooks named_property_hooks;
- static IndexedPropertyHooks indexed_property_hooks;
-};
-
-ProxyHandler::NamedPropertyHooks
-MozjsConstantsInterfaceHandler::named_property_hooks = {
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
-};
-ProxyHandler::IndexedPropertyHooks
-MozjsConstantsInterfaceHandler::indexed_property_hooks = {
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
-};
-
-static base::LazyInstance<MozjsConstantsInterfaceHandler>
- proxy_handler;
-
-JSBool get_INTEGER_CONSTANT(
- JSContext* context, JS::HandleObject object, JS::HandleId id,
- JS::MutableHandleValue vp) {
- COMPILE_ASSERT(ConstantsInterface::kIntegerConstant == 5,
- ValueForConstantsInterface_kIntegerConstantDoesNotMatchIDL);
- MozjsExceptionState exception_state(context);
- JS::RootedValue result_value(context);
- ToJSValue(context, 5, &result_value);
- if (!exception_state.is_exception_set()) {
- vp.set(result_value);
- }
- return !exception_state.is_exception_set();
-}
-
-JSBool get_DOUBLE_CONSTANT(
- JSContext* context, JS::HandleObject object, JS::HandleId id,
- JS::MutableHandleValue vp) {
- DCHECK_EQ(2.718, ConstantsInterface::kDoubleConstant) <<
- "The value for ConstantsInterface::kDoubleConstant does not match "
- "the value in the interface definition.";
- MozjsExceptionState exception_state(context);
- JS::RootedValue result_value(context);
- ToJSValue(context, 2.718, &result_value);
- if (!exception_state.is_exception_set()) {
- vp.set(result_value);
- }
- return !exception_state.is_exception_set();
-}
-
-JSBool HasInstance(JSContext *context, JS::HandleObject type,
- JS::MutableHandleValue vp, JSBool *success) {
- JS::RootedObject global_object(
- context, JS_GetGlobalForObject(context, type));
- DCHECK(global_object);
-
- JS::RootedObject prototype(
- context, MozjsConstantsInterface::GetPrototype(context, global_object));
-
- // |IsDelegate| walks the prototype chain of an object returning true if
- // .prototype is found.
- bool is_delegate;
- if (!IsDelegate(context, prototype, vp, &is_delegate)) {
- *success = false;
- return false;
- }
-
- *success = is_delegate;
- return true;
-}
-
-InterfaceData* CreateCachedInterfaceData() {
- InterfaceData* interface_data = new InterfaceData();
- memset(&interface_data->instance_class_definition, 0,
- sizeof(interface_data->instance_class_definition));
- memset(&interface_data->prototype_class_definition, 0,
- sizeof(interface_data->prototype_class_definition));
- memset(&interface_data->interface_object_class_definition, 0,
- sizeof(interface_data->interface_object_class_definition));
-
- JSClass* instance_class = &interface_data->instance_class_definition;
- const int kGlobalFlags = 0;
- instance_class->name = "ConstantsInterface";
- instance_class->flags = kGlobalFlags | JSCLASS_HAS_PRIVATE;
- instance_class->addProperty = JS_PropertyStub;
- instance_class->delProperty = JS_DeletePropertyStub;
- instance_class->getProperty = JS_PropertyStub;
- instance_class->setProperty = JS_StrictPropertyStub;
- instance_class->enumerate = JS_EnumerateStub;
- instance_class->resolve = JS_ResolveStub;
- instance_class->convert = JS_ConvertStub;
- // Function to be called before on object of this class is garbage collected.
- instance_class->finalize = &WrapperPrivate::Finalizer;
- // Called to trace objects that can be referenced from this object.
- instance_class->trace = &WrapperPrivate::Trace;
-
- JSClass* prototype_class = &interface_data->prototype_class_definition;
- prototype_class->name = "ConstantsInterfacePrototype";
- prototype_class->flags = 0;
- prototype_class->addProperty = JS_PropertyStub;
- prototype_class->delProperty = JS_DeletePropertyStub;
- prototype_class->getProperty = JS_PropertyStub;
- prototype_class->setProperty = JS_StrictPropertyStub;
- prototype_class->enumerate = JS_EnumerateStub;
- prototype_class->resolve = JS_ResolveStub;
- prototype_class->convert = JS_ConvertStub;
-
- JSClass* interface_object_class =
- &interface_data->interface_object_class_definition;
- interface_object_class->name = "ConstantsInterfaceConstructor";
- interface_object_class->flags = 0;
- interface_object_class->addProperty = JS_PropertyStub;
- interface_object_class->delProperty = JS_DeletePropertyStub;
- interface_object_class->getProperty = JS_PropertyStub;
- interface_object_class->setProperty = JS_StrictPropertyStub;
- interface_object_class->enumerate = JS_EnumerateStub;
- interface_object_class->resolve = JS_ResolveStub;
- interface_object_class->convert = JS_ConvertStub;
- interface_object_class->hasInstance = &HasInstance;
- return interface_data;
-}
-
-
-const JSPropertySpec prototype_properties[] = {
- {
- "INTEGER_CONSTANT", 0,
- JSPROP_PERMANENT | JSPROP_READONLY | JSPROP_ENUMERATE,
- JSOP_WRAPPER(&get_INTEGER_CONSTANT),
- JSOP_NULLWRAPPER,
- },
- {
- "DOUBLE_CONSTANT", 0,
- JSPROP_PERMANENT | JSPROP_READONLY | JSPROP_ENUMERATE,
- JSOP_WRAPPER(&get_DOUBLE_CONSTANT),
- JSOP_NULLWRAPPER,
- },
- JS_PS_END
-};
-
-const JSFunctionSpec prototype_functions[] = {
- JS_FS_END
-};
-
-const JSPropertySpec interface_object_properties[] = {
- {
- "INTEGER_CONSTANT", 0,
- JSPROP_PERMANENT | JSPROP_READONLY | JSPROP_ENUMERATE,
- JSOP_WRAPPER(&get_INTEGER_CONSTANT),
- JSOP_NULLWRAPPER,
- },
- {
- "DOUBLE_CONSTANT", 0,
- JSPROP_PERMANENT | JSPROP_READONLY | JSPROP_ENUMERATE,
- JSOP_WRAPPER(&get_DOUBLE_CONSTANT),
- JSOP_NULLWRAPPER,
- },
- JS_PS_END
-};
-
-const JSFunctionSpec interface_object_functions[] = {
- JS_FS_END
-};
-
-const JSPropertySpec own_properties[] = {
- JS_PS_END
-};
-
-void InitializePrototypeAndInterfaceObject(
- InterfaceData* interface_data, JSContext* context,
- JS::HandleObject global_object) {
- DCHECK(!interface_data->prototype);
- DCHECK(!interface_data->interface_object);
- DCHECK(JS_IsGlobalObject(global_object));
-
- JS::RootedObject parent_prototype(
- context, JS_GetObjectPrototype(context, global_object));
- DCHECK(parent_prototype);
-
- // Create the Prototype object.
- interface_data->prototype = JS_NewObjectWithGivenProto(
- context, &interface_data->prototype_class_definition, parent_prototype,
- NULL);
- bool success = JS_DefineProperties(
- context, interface_data->prototype, prototype_properties);
- DCHECK(success);
- success = JS_DefineFunctions(
- context, interface_data->prototype, prototype_functions);
- DCHECK(success);
-
- JS::RootedObject function_prototype(
- context, JS_GetFunctionPrototype(context, global_object));
- DCHECK(function_prototype);
- // Create the Interface object.
- interface_data->interface_object = JS_NewObjectWithGivenProto(
- context, &interface_data->interface_object_class_definition,
- function_prototype, NULL);
-
- // Add the InterfaceObject.name property.
- JS::RootedObject rooted_interface_object(
- context, interface_data->interface_object);
- JS::RootedValue name_value(context);
- const char name[] =
- "ConstantsInterface";
- name_value.setString(JS_NewStringCopyZ(context, name));
- success =
- JS_DefineProperty(context, rooted_interface_object, "name", name_value,
- JS_PropertyStub, JS_StrictPropertyStub,
- JSPROP_READONLY);
- DCHECK(success);
-
- // Define interface object properties (including constants).
- success = JS_DefineProperties(context, rooted_interface_object,
- interface_object_properties);
- DCHECK(success);
- // Define interface object functions (static).
- success = JS_DefineFunctions(context, rooted_interface_object,
- interface_object_functions);
- DCHECK(success);
-
-
- // Set the Prototype.constructor and Constructor.prototype properties.
- DCHECK(interface_data->interface_object);
- DCHECK(interface_data->prototype);
- JS::RootedObject rooted_prototype(context, interface_data->prototype);
- success = JS_LinkConstructorAndPrototype(
- context,
- rooted_interface_object,
- rooted_prototype);
- DCHECK(success);
-}
-
-InterfaceData* GetInterfaceData(JSContext* context) {
- MozjsGlobalEnvironment* global_environment =
- static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context));
- // Use the address of the properties definition for this interface as a
- // unique key for looking up the InterfaceData for this interface.
- intptr_t key = reinterpret_cast<intptr_t>(&own_properties);
- InterfaceData* interface_data = global_environment->GetInterfaceData(key);
- if (!interface_data) {
- interface_data = CreateCachedInterfaceData();
- DCHECK(interface_data);
- global_environment->CacheInterfaceData(key, interface_data);
- DCHECK_EQ(interface_data, global_environment->GetInterfaceData(key));
- }
- return interface_data;
-}
-
-} // namespace
-
-// static
-JSObject* MozjsConstantsInterface::CreateProxy(
- JSContext* context, const scoped_refptr<Wrappable>& wrappable) {
- DCHECK(MozjsGlobalEnvironment::GetFromContext(context));
- JS::RootedObject global_object(
- context,
- MozjsGlobalEnvironment::GetFromContext(context)->global_object());
- DCHECK(global_object);
-
- InterfaceData* interface_data = GetInterfaceData(context);
- JS::RootedObject prototype(context, GetPrototype(context, global_object));
- DCHECK(prototype);
- JS::RootedObject new_object(context, JS_NewObjectWithGivenProto(
- context, &interface_data->instance_class_definition, prototype, NULL));
- DCHECK(new_object);
- JS::RootedObject proxy(context,
- ProxyHandler::NewProxy(context, new_object, prototype, NULL,
- proxy_handler.Pointer()));
- WrapperPrivate::AddPrivateData(context, proxy, wrappable);
- return proxy;
-}
-
-//static
-const JSClass* MozjsConstantsInterface::PrototypeClass(
- JSContext* context) {
- DCHECK(MozjsGlobalEnvironment::GetFromContext(context));
- JS::RootedObject global_object(
- context,
- MozjsGlobalEnvironment::GetFromContext(context)->global_object());
- DCHECK(global_object);
-
- JS::RootedObject prototype(context, GetPrototype(context, global_object));
- JSClass* proto_class = JS_GetClass(*prototype.address());
- return proto_class;
-}
-
-// static
-JSObject* MozjsConstantsInterface::GetPrototype(
- JSContext* context, JS::HandleObject global_object) {
- DCHECK(JS_IsGlobalObject(global_object));
-
- InterfaceData* interface_data = GetInterfaceData(context);
- if (!interface_data->prototype) {
- // Create new prototype that has all the props and methods
- InitializePrototypeAndInterfaceObject(
- interface_data, context, global_object);
- }
- DCHECK(interface_data->prototype);
- return interface_data->prototype;
-}
-
-// static
-JSObject* MozjsConstantsInterface::GetInterfaceObject(
- JSContext* context, JS::HandleObject global_object) {
- DCHECK(JS_IsGlobalObject(global_object));
-
- InterfaceData* interface_data = GetInterfaceData(context);
- if (!interface_data->interface_object) {
- InitializePrototypeAndInterfaceObject(
- interface_data, context, global_object);
- }
- DCHECK(interface_data->interface_object);
- return interface_data->interface_object;
-}
-
-
-namespace {
-} // namespace
-
-
-} // namespace testing
-} // namespace bindings
-} // namespace cobalt
diff --git a/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_constants_interface.h b/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_constants_interface.h
deleted file mode 100644
index 7bc86ba..0000000
--- a/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_constants_interface.h
+++ /dev/null
@@ -1,52 +0,0 @@
-// Copyright 2017 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/mozjs/templates/interface.h.template
-
-#ifndef MozjsConstantsInterface_h
-#define MozjsConstantsInterface_h
-
-#include "base/hash_tables.h"
-#include "base/lazy_instance.h"
-#include "base/memory/ref_counted.h"
-#include "base/threading/thread_checker.h"
-#include "cobalt/base/polymorphic_downcast.h"
-#include "cobalt/script/wrappable.h"
-#include "cobalt/bindings/testing/constants_interface.h"
-
-#include "third_party/mozjs/js/src/jsapi.h"
-
-namespace cobalt {
-namespace bindings {
-namespace testing {
-
-class MozjsConstantsInterface {
- public:
- static JSObject* CreateProxy(JSContext* context,
- const scoped_refptr<script::Wrappable>& wrappable);
- static const JSClass* PrototypeClass(JSContext* context);
- static JSObject* GetPrototype(JSContext* context,
- JS::HandleObject global_object);
- static JSObject* GetInterfaceObject(JSContext* context,
- JS::HandleObject global_object);
-};
-
-} // namespace testing
-} // namespace bindings
-} // namespace cobalt
-
-#endif // MozjsConstantsInterface_h
diff --git a/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_constructor_interface.cc b/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_constructor_interface.cc
deleted file mode 100644
index cbe05b6..0000000
--- a/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_constructor_interface.cc
+++ /dev/null
@@ -1,458 +0,0 @@
-// Copyright 2017 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/mozjs/templates/interface.cc.template
-
-#include "cobalt/bindings/testing/mozjs_constructor_interface.h"
-
-#include "base/debug/trace_event.h"
-#include "cobalt/base/polymorphic_downcast.h"
-#include "cobalt/script/global_environment.h"
-#include "cobalt/script/opaque_handle.h"
-#include "cobalt/script/script_value.h"
-
-#include "mozjs_gen_type_conversion.h"
-
-#include "base/lazy_instance.h"
-#include "cobalt/script/exception_state.h"
-#include "cobalt/script/mozjs/callback_function_conversion.h"
-#include "cobalt/script/mozjs/conversion_helpers.h"
-#include "cobalt/script/mozjs/mozjs_callback_function.h"
-#include "cobalt/script/mozjs/mozjs_exception_state.h"
-#include "cobalt/script/mozjs/mozjs_global_environment.h"
-#include "cobalt/script/mozjs/mozjs_object_handle.h"
-#include "cobalt/script/mozjs/mozjs_property_enumerator.h"
-#include "cobalt/script/mozjs/mozjs_user_object_holder.h"
-#include "cobalt/script/mozjs/mozjs_value_handle.h"
-#include "cobalt/script/mozjs/native_promise.h"
-#include "cobalt/script/mozjs/proxy_handler.h"
-#include "cobalt/script/mozjs/type_traits.h"
-#include "cobalt/script/mozjs/wrapper_factory.h"
-#include "cobalt/script/mozjs/wrapper_private.h"
-#include "cobalt/script/property_enumerator.h"
-#include "cobalt/script/sequence.h"
-#include "third_party/mozjs/js/src/jsapi.h"
-#include "third_party/mozjs/js/src/jsfriendapi.h"
-
-namespace {
-using cobalt::bindings::testing::ConstructorInterface;
-using cobalt::bindings::testing::MozjsConstructorInterface;
-using cobalt::script::CallbackInterfaceTraits;
-using cobalt::script::GlobalEnvironment;
-using cobalt::script::OpaqueHandle;
-using cobalt::script::OpaqueHandleHolder;
-using cobalt::script::ScriptValue;
-using cobalt::script::ValueHandle;
-using cobalt::script::Wrappable;
-
-using cobalt::script::CallbackFunction;
-using cobalt::script::CallbackInterfaceTraits;
-using cobalt::script::ExceptionState;
-using cobalt::script::Wrappable;
-using cobalt::script::mozjs::FromJSValue;
-using cobalt::script::mozjs::InterfaceData;
-using cobalt::script::mozjs::MozjsCallbackFunction;
-using cobalt::script::mozjs::MozjsExceptionState;
-using cobalt::script::mozjs::MozjsGlobalEnvironment;
-using cobalt::script::mozjs::MozjsPropertyEnumerator;
-using cobalt::script::mozjs::MozjsUserObjectHolder;
-using cobalt::script::mozjs::ProxyHandler;
-using cobalt::script::mozjs::ToJSValue;
-using cobalt::script::mozjs::TypeTraits;
-using cobalt::script::mozjs::WrapperFactory;
-using cobalt::script::mozjs::WrapperPrivate;
-using cobalt::script::mozjs::kConversionFlagClamped;
-using cobalt::script::mozjs::kConversionFlagNullable;
-using cobalt::script::mozjs::kConversionFlagRestricted;
-using cobalt::script::mozjs::kConversionFlagTreatNullAsEmptyString;
-using cobalt::script::mozjs::kConversionFlagTreatUndefinedAsEmptyString;
-using cobalt::script::mozjs::kNoConversionFlags;
-} // namespace
-
-namespace cobalt {
-namespace bindings {
-namespace testing {
-
-namespace {
-
-class MozjsConstructorInterfaceHandler : public ProxyHandler {
- public:
- MozjsConstructorInterfaceHandler()
- : ProxyHandler(indexed_property_hooks, named_property_hooks) {}
-
- private:
- static NamedPropertyHooks named_property_hooks;
- static IndexedPropertyHooks indexed_property_hooks;
-};
-
-ProxyHandler::NamedPropertyHooks
-MozjsConstructorInterfaceHandler::named_property_hooks = {
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
-};
-ProxyHandler::IndexedPropertyHooks
-MozjsConstructorInterfaceHandler::indexed_property_hooks = {
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
-};
-
-static base::LazyInstance<MozjsConstructorInterfaceHandler>
- proxy_handler;
-
-JSBool Constructor(JSContext* context, unsigned int argc, JS::Value* vp);
-JSBool HasInstance(JSContext *context, JS::HandleObject type,
- JS::MutableHandleValue vp, JSBool *success) {
- JS::RootedObject global_object(
- context, JS_GetGlobalForObject(context, type));
- DCHECK(global_object);
-
- JS::RootedObject prototype(
- context, MozjsConstructorInterface::GetPrototype(context, global_object));
-
- // |IsDelegate| walks the prototype chain of an object returning true if
- // .prototype is found.
- bool is_delegate;
- if (!IsDelegate(context, prototype, vp, &is_delegate)) {
- *success = false;
- return false;
- }
-
- *success = is_delegate;
- return true;
-}
-
-InterfaceData* CreateCachedInterfaceData() {
- InterfaceData* interface_data = new InterfaceData();
- memset(&interface_data->instance_class_definition, 0,
- sizeof(interface_data->instance_class_definition));
- memset(&interface_data->prototype_class_definition, 0,
- sizeof(interface_data->prototype_class_definition));
- memset(&interface_data->interface_object_class_definition, 0,
- sizeof(interface_data->interface_object_class_definition));
-
- JSClass* instance_class = &interface_data->instance_class_definition;
- const int kGlobalFlags = 0;
- instance_class->name = "ConstructorInterface";
- instance_class->flags = kGlobalFlags | JSCLASS_HAS_PRIVATE;
- instance_class->addProperty = JS_PropertyStub;
- instance_class->delProperty = JS_DeletePropertyStub;
- instance_class->getProperty = JS_PropertyStub;
- instance_class->setProperty = JS_StrictPropertyStub;
- instance_class->enumerate = JS_EnumerateStub;
- instance_class->resolve = JS_ResolveStub;
- instance_class->convert = JS_ConvertStub;
- // Function to be called before on object of this class is garbage collected.
- instance_class->finalize = &WrapperPrivate::Finalizer;
- // Called to trace objects that can be referenced from this object.
- instance_class->trace = &WrapperPrivate::Trace;
-
- JSClass* prototype_class = &interface_data->prototype_class_definition;
- prototype_class->name = "ConstructorInterfacePrototype";
- prototype_class->flags = 0;
- prototype_class->addProperty = JS_PropertyStub;
- prototype_class->delProperty = JS_DeletePropertyStub;
- prototype_class->getProperty = JS_PropertyStub;
- prototype_class->setProperty = JS_StrictPropertyStub;
- prototype_class->enumerate = JS_EnumerateStub;
- prototype_class->resolve = JS_ResolveStub;
- prototype_class->convert = JS_ConvertStub;
-
- JSClass* interface_object_class =
- &interface_data->interface_object_class_definition;
- interface_object_class->name = "ConstructorInterfaceConstructor";
- interface_object_class->flags = 0;
- interface_object_class->addProperty = JS_PropertyStub;
- interface_object_class->delProperty = JS_DeletePropertyStub;
- interface_object_class->getProperty = JS_PropertyStub;
- interface_object_class->setProperty = JS_StrictPropertyStub;
- interface_object_class->enumerate = JS_EnumerateStub;
- interface_object_class->resolve = JS_ResolveStub;
- interface_object_class->convert = JS_ConvertStub;
- interface_object_class->hasInstance = &HasInstance;
- interface_object_class->construct = Constructor;
- return interface_data;
-}
-
-
-const JSPropertySpec prototype_properties[] = {
- JS_PS_END
-};
-
-const JSFunctionSpec prototype_functions[] = {
- JS_FS_END
-};
-
-const JSPropertySpec interface_object_properties[] = {
- JS_PS_END
-};
-
-const JSFunctionSpec interface_object_functions[] = {
- JS_FS_END
-};
-
-const JSPropertySpec own_properties[] = {
- JS_PS_END
-};
-
-void InitializePrototypeAndInterfaceObject(
- InterfaceData* interface_data, JSContext* context,
- JS::HandleObject global_object) {
- DCHECK(!interface_data->prototype);
- DCHECK(!interface_data->interface_object);
- DCHECK(JS_IsGlobalObject(global_object));
-
- JS::RootedObject parent_prototype(
- context, JS_GetObjectPrototype(context, global_object));
- DCHECK(parent_prototype);
-
- // Create the Prototype object.
- interface_data->prototype = JS_NewObjectWithGivenProto(
- context, &interface_data->prototype_class_definition, parent_prototype,
- NULL);
- bool success = JS_DefineProperties(
- context, interface_data->prototype, prototype_properties);
- DCHECK(success);
- success = JS_DefineFunctions(
- context, interface_data->prototype, prototype_functions);
- DCHECK(success);
-
- JS::RootedObject function_prototype(
- context, JS_GetFunctionPrototype(context, global_object));
- DCHECK(function_prototype);
- // Create the Interface object.
- interface_data->interface_object = JS_NewObjectWithGivenProto(
- context, &interface_data->interface_object_class_definition,
- function_prototype, NULL);
-
- // Add the InterfaceObject.name property.
- JS::RootedObject rooted_interface_object(
- context, interface_data->interface_object);
- JS::RootedValue name_value(context);
- const char name[] =
- "ConstructorInterface";
- name_value.setString(JS_NewStringCopyZ(context, name));
- success =
- JS_DefineProperty(context, rooted_interface_object, "name", name_value,
- JS_PropertyStub, JS_StrictPropertyStub,
- JSPROP_READONLY);
- DCHECK(success);
-
- // Add the InterfaceObject.length property. It is set to the length of the
- // shortest argument list of all overload constructors.
- JS::RootedValue length_value(context);
- length_value.setInt32(0);
- success =
- JS_DefineProperty(context, rooted_interface_object, "length",
- length_value, JS_PropertyStub, JS_StrictPropertyStub,
- JSPROP_READONLY);
- DCHECK(success);
-
- // Define interface object properties (including constants).
- success = JS_DefineProperties(context, rooted_interface_object,
- interface_object_properties);
- DCHECK(success);
- // Define interface object functions (static).
- success = JS_DefineFunctions(context, rooted_interface_object,
- interface_object_functions);
- DCHECK(success);
-
-
- // Set the Prototype.constructor and Constructor.prototype properties.
- DCHECK(interface_data->interface_object);
- DCHECK(interface_data->prototype);
- JS::RootedObject rooted_prototype(context, interface_data->prototype);
- success = JS_LinkConstructorAndPrototype(
- context,
- rooted_interface_object,
- rooted_prototype);
- DCHECK(success);
-}
-
-InterfaceData* GetInterfaceData(JSContext* context) {
- MozjsGlobalEnvironment* global_environment =
- static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context));
- // Use the address of the properties definition for this interface as a
- // unique key for looking up the InterfaceData for this interface.
- intptr_t key = reinterpret_cast<intptr_t>(&own_properties);
- InterfaceData* interface_data = global_environment->GetInterfaceData(key);
- if (!interface_data) {
- interface_data = CreateCachedInterfaceData();
- DCHECK(interface_data);
- global_environment->CacheInterfaceData(key, interface_data);
- DCHECK_EQ(interface_data, global_environment->GetInterfaceData(key));
- }
- return interface_data;
-}
-
-} // namespace
-
-// static
-JSObject* MozjsConstructorInterface::CreateProxy(
- JSContext* context, const scoped_refptr<Wrappable>& wrappable) {
- DCHECK(MozjsGlobalEnvironment::GetFromContext(context));
- JS::RootedObject global_object(
- context,
- MozjsGlobalEnvironment::GetFromContext(context)->global_object());
- DCHECK(global_object);
-
- InterfaceData* interface_data = GetInterfaceData(context);
- JS::RootedObject prototype(context, GetPrototype(context, global_object));
- DCHECK(prototype);
- JS::RootedObject new_object(context, JS_NewObjectWithGivenProto(
- context, &interface_data->instance_class_definition, prototype, NULL));
- DCHECK(new_object);
- JS::RootedObject proxy(context,
- ProxyHandler::NewProxy(context, new_object, prototype, NULL,
- proxy_handler.Pointer()));
- WrapperPrivate::AddPrivateData(context, proxy, wrappable);
- return proxy;
-}
-
-//static
-const JSClass* MozjsConstructorInterface::PrototypeClass(
- JSContext* context) {
- DCHECK(MozjsGlobalEnvironment::GetFromContext(context));
- JS::RootedObject global_object(
- context,
- MozjsGlobalEnvironment::GetFromContext(context)->global_object());
- DCHECK(global_object);
-
- JS::RootedObject prototype(context, GetPrototype(context, global_object));
- JSClass* proto_class = JS_GetClass(*prototype.address());
- return proto_class;
-}
-
-// static
-JSObject* MozjsConstructorInterface::GetPrototype(
- JSContext* context, JS::HandleObject global_object) {
- DCHECK(JS_IsGlobalObject(global_object));
-
- InterfaceData* interface_data = GetInterfaceData(context);
- if (!interface_data->prototype) {
- // Create new prototype that has all the props and methods
- InitializePrototypeAndInterfaceObject(
- interface_data, context, global_object);
- }
- DCHECK(interface_data->prototype);
- return interface_data->prototype;
-}
-
-// static
-JSObject* MozjsConstructorInterface::GetInterfaceObject(
- JSContext* context, JS::HandleObject global_object) {
- DCHECK(JS_IsGlobalObject(global_object));
-
- InterfaceData* interface_data = GetInterfaceData(context);
- if (!interface_data->interface_object) {
- InitializePrototypeAndInterfaceObject(
- interface_data, context, global_object);
- }
- DCHECK(interface_data->interface_object);
- return interface_data->interface_object;
-}
-
-
-namespace {
-JSBool Constructor1(
- JSContext* context, unsigned int argc, JS::Value* vp) {
- MozjsExceptionState exception_state(context);
- JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
-
- scoped_refptr<ConstructorInterface> new_object =
- new ConstructorInterface();
- JS::RootedValue result_value(context);
- ToJSValue(context, new_object, &result_value);
- DCHECK(result_value.isObject());
- JS::RootedObject result_object(context, JSVAL_TO_OBJECT(result_value));
- args.rval().setObject(*result_object);
- return true;
-}
-
-JSBool Constructor2(
- JSContext* context, unsigned int argc, JS::Value* vp) {
- MozjsExceptionState exception_state(context);
- JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
- const size_t kMinArguments = 1;
- if (args.length() < kMinArguments) {
- exception_state.SetSimpleException(script::kInvalidNumberOfArguments);
- return false;
- }
- // Non-optional arguments
- TypeTraits<bool >::ConversionType arg;
-
- DCHECK_LT(0, args.length());
- JS::RootedValue non_optional_value0(
- context, args[0]);
- FromJSValue(context,
- non_optional_value0,
- kNoConversionFlags,
- &exception_state, &arg);
- if (exception_state.is_exception_set()) {
- return false;
- }
-
- scoped_refptr<ConstructorInterface> new_object =
- new ConstructorInterface(arg);
- JS::RootedValue result_value(context);
- ToJSValue(context, new_object, &result_value);
- DCHECK(result_value.isObject());
- JS::RootedObject result_object(context, JSVAL_TO_OBJECT(result_value));
- args.rval().setObject(*result_object);
- return true;
-}
-
-JSBool Constructor(JSContext* context, unsigned int argc, JS::Value* vp) {
- JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
- switch(argc) {
- case(0): {
- // Overload resolution algorithm details found here:
- // http://heycam.github.io/webidl/#dfn-overload-resolution-algorithm
- if (true) {
- return Constructor1(
- context, argc, vp);
- }
- break;
- }
- case(1): {
- // Overload resolution algorithm details found here:
- // http://heycam.github.io/webidl/#dfn-overload-resolution-algorithm
- if (true) {
- return Constructor2(
- context, argc, vp);
- }
- break;
- }
- }
- // Invalid number of args
- // http://heycam.github.io/webidl/#dfn-overload-resolution-algorithm
- // 4. If S is empty, then throw a TypeError.
- MozjsExceptionState exception_state(context);
- exception_state.SetSimpleException(script::kInvalidNumberOfArguments);
- return false;
-}
-} // namespace
-
-
-} // namespace testing
-} // namespace bindings
-} // namespace cobalt
diff --git a/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_constructor_interface.h b/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_constructor_interface.h
deleted file mode 100644
index 93f4a10..0000000
--- a/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_constructor_interface.h
+++ /dev/null
@@ -1,52 +0,0 @@
-// Copyright 2017 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/mozjs/templates/interface.h.template
-
-#ifndef MozjsConstructorInterface_h
-#define MozjsConstructorInterface_h
-
-#include "base/hash_tables.h"
-#include "base/lazy_instance.h"
-#include "base/memory/ref_counted.h"
-#include "base/threading/thread_checker.h"
-#include "cobalt/base/polymorphic_downcast.h"
-#include "cobalt/script/wrappable.h"
-#include "cobalt/bindings/testing/constructor_interface.h"
-
-#include "third_party/mozjs/js/src/jsapi.h"
-
-namespace cobalt {
-namespace bindings {
-namespace testing {
-
-class MozjsConstructorInterface {
- public:
- static JSObject* CreateProxy(JSContext* context,
- const scoped_refptr<script::Wrappable>& wrappable);
- static const JSClass* PrototypeClass(JSContext* context);
- static JSObject* GetPrototype(JSContext* context,
- JS::HandleObject global_object);
- static JSObject* GetInterfaceObject(JSContext* context,
- JS::HandleObject global_object);
-};
-
-} // namespace testing
-} // namespace bindings
-} // namespace cobalt
-
-#endif // MozjsConstructorInterface_h
diff --git a/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_constructor_with_arguments_interface.cc b/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_constructor_with_arguments_interface.cc
deleted file mode 100644
index 754e7d5..0000000
--- a/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_constructor_with_arguments_interface.cc
+++ /dev/null
@@ -1,581 +0,0 @@
-// Copyright 2017 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/mozjs/templates/interface.cc.template
-
-#include "cobalt/bindings/testing/mozjs_constructor_with_arguments_interface.h"
-
-#include "base/debug/trace_event.h"
-#include "cobalt/base/polymorphic_downcast.h"
-#include "cobalt/script/global_environment.h"
-#include "cobalt/script/opaque_handle.h"
-#include "cobalt/script/script_value.h"
-
-#include "mozjs_gen_type_conversion.h"
-
-#include "base/lazy_instance.h"
-#include "cobalt/script/exception_state.h"
-#include "cobalt/script/mozjs/callback_function_conversion.h"
-#include "cobalt/script/mozjs/conversion_helpers.h"
-#include "cobalt/script/mozjs/mozjs_callback_function.h"
-#include "cobalt/script/mozjs/mozjs_exception_state.h"
-#include "cobalt/script/mozjs/mozjs_global_environment.h"
-#include "cobalt/script/mozjs/mozjs_object_handle.h"
-#include "cobalt/script/mozjs/mozjs_property_enumerator.h"
-#include "cobalt/script/mozjs/mozjs_user_object_holder.h"
-#include "cobalt/script/mozjs/mozjs_value_handle.h"
-#include "cobalt/script/mozjs/native_promise.h"
-#include "cobalt/script/mozjs/proxy_handler.h"
-#include "cobalt/script/mozjs/type_traits.h"
-#include "cobalt/script/mozjs/wrapper_factory.h"
-#include "cobalt/script/mozjs/wrapper_private.h"
-#include "cobalt/script/property_enumerator.h"
-#include "cobalt/script/sequence.h"
-#include "third_party/mozjs/js/src/jsapi.h"
-#include "third_party/mozjs/js/src/jsfriendapi.h"
-
-namespace {
-using cobalt::bindings::testing::ConstructorWithArgumentsInterface;
-using cobalt::bindings::testing::MozjsConstructorWithArgumentsInterface;
-using cobalt::script::CallbackInterfaceTraits;
-using cobalt::script::GlobalEnvironment;
-using cobalt::script::OpaqueHandle;
-using cobalt::script::OpaqueHandleHolder;
-using cobalt::script::ScriptValue;
-using cobalt::script::ValueHandle;
-using cobalt::script::Wrappable;
-
-using cobalt::script::CallbackFunction;
-using cobalt::script::CallbackInterfaceTraits;
-using cobalt::script::ExceptionState;
-using cobalt::script::Wrappable;
-using cobalt::script::mozjs::FromJSValue;
-using cobalt::script::mozjs::InterfaceData;
-using cobalt::script::mozjs::MozjsCallbackFunction;
-using cobalt::script::mozjs::MozjsExceptionState;
-using cobalt::script::mozjs::MozjsGlobalEnvironment;
-using cobalt::script::mozjs::MozjsPropertyEnumerator;
-using cobalt::script::mozjs::MozjsUserObjectHolder;
-using cobalt::script::mozjs::ProxyHandler;
-using cobalt::script::mozjs::ToJSValue;
-using cobalt::script::mozjs::TypeTraits;
-using cobalt::script::mozjs::WrapperFactory;
-using cobalt::script::mozjs::WrapperPrivate;
-using cobalt::script::mozjs::kConversionFlagClamped;
-using cobalt::script::mozjs::kConversionFlagNullable;
-using cobalt::script::mozjs::kConversionFlagRestricted;
-using cobalt::script::mozjs::kConversionFlagTreatNullAsEmptyString;
-using cobalt::script::mozjs::kConversionFlagTreatUndefinedAsEmptyString;
-using cobalt::script::mozjs::kNoConversionFlags;
-} // namespace
-
-namespace cobalt {
-namespace bindings {
-namespace testing {
-
-namespace {
-
-class MozjsConstructorWithArgumentsInterfaceHandler : public ProxyHandler {
- public:
- MozjsConstructorWithArgumentsInterfaceHandler()
- : ProxyHandler(indexed_property_hooks, named_property_hooks) {}
-
- private:
- static NamedPropertyHooks named_property_hooks;
- static IndexedPropertyHooks indexed_property_hooks;
-};
-
-ProxyHandler::NamedPropertyHooks
-MozjsConstructorWithArgumentsInterfaceHandler::named_property_hooks = {
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
-};
-ProxyHandler::IndexedPropertyHooks
-MozjsConstructorWithArgumentsInterfaceHandler::indexed_property_hooks = {
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
-};
-
-static base::LazyInstance<MozjsConstructorWithArgumentsInterfaceHandler>
- proxy_handler;
-
-JSBool Constructor(JSContext* context, unsigned int argc, JS::Value* vp);
-JSBool HasInstance(JSContext *context, JS::HandleObject type,
- JS::MutableHandleValue vp, JSBool *success) {
- JS::RootedObject global_object(
- context, JS_GetGlobalForObject(context, type));
- DCHECK(global_object);
-
- JS::RootedObject prototype(
- context, MozjsConstructorWithArgumentsInterface::GetPrototype(context, global_object));
-
- // |IsDelegate| walks the prototype chain of an object returning true if
- // .prototype is found.
- bool is_delegate;
- if (!IsDelegate(context, prototype, vp, &is_delegate)) {
- *success = false;
- return false;
- }
-
- *success = is_delegate;
- return true;
-}
-
-InterfaceData* CreateCachedInterfaceData() {
- InterfaceData* interface_data = new InterfaceData();
- memset(&interface_data->instance_class_definition, 0,
- sizeof(interface_data->instance_class_definition));
- memset(&interface_data->prototype_class_definition, 0,
- sizeof(interface_data->prototype_class_definition));
- memset(&interface_data->interface_object_class_definition, 0,
- sizeof(interface_data->interface_object_class_definition));
-
- JSClass* instance_class = &interface_data->instance_class_definition;
- const int kGlobalFlags = 0;
- instance_class->name = "ConstructorWithArgumentsInterface";
- instance_class->flags = kGlobalFlags | JSCLASS_HAS_PRIVATE;
- instance_class->addProperty = JS_PropertyStub;
- instance_class->delProperty = JS_DeletePropertyStub;
- instance_class->getProperty = JS_PropertyStub;
- instance_class->setProperty = JS_StrictPropertyStub;
- instance_class->enumerate = JS_EnumerateStub;
- instance_class->resolve = JS_ResolveStub;
- instance_class->convert = JS_ConvertStub;
- // Function to be called before on object of this class is garbage collected.
- instance_class->finalize = &WrapperPrivate::Finalizer;
- // Called to trace objects that can be referenced from this object.
- instance_class->trace = &WrapperPrivate::Trace;
-
- JSClass* prototype_class = &interface_data->prototype_class_definition;
- prototype_class->name = "ConstructorWithArgumentsInterfacePrototype";
- prototype_class->flags = 0;
- prototype_class->addProperty = JS_PropertyStub;
- prototype_class->delProperty = JS_DeletePropertyStub;
- prototype_class->getProperty = JS_PropertyStub;
- prototype_class->setProperty = JS_StrictPropertyStub;
- prototype_class->enumerate = JS_EnumerateStub;
- prototype_class->resolve = JS_ResolveStub;
- prototype_class->convert = JS_ConvertStub;
-
- JSClass* interface_object_class =
- &interface_data->interface_object_class_definition;
- interface_object_class->name = "ConstructorWithArgumentsInterfaceConstructor";
- interface_object_class->flags = 0;
- interface_object_class->addProperty = JS_PropertyStub;
- interface_object_class->delProperty = JS_DeletePropertyStub;
- interface_object_class->getProperty = JS_PropertyStub;
- interface_object_class->setProperty = JS_StrictPropertyStub;
- interface_object_class->enumerate = JS_EnumerateStub;
- interface_object_class->resolve = JS_ResolveStub;
- interface_object_class->convert = JS_ConvertStub;
- interface_object_class->hasInstance = &HasInstance;
- interface_object_class->construct = Constructor;
- return interface_data;
-}
-
-JSBool get_longArg(
- JSContext* context, JS::HandleObject object, JS::HandleId id,
- JS::MutableHandleValue vp) {
- const JSClass* proto_class =
- MozjsConstructorWithArgumentsInterface::PrototypeClass(context);
- if (proto_class == JS_GetClass(object)) {
- // Simply returns true if the object is this class's prototype object.
- // There is no need to return any value due to the object is not a platform
- // object. The execution reaches here when Object.getOwnPropertyDescriptor
- // gets called on native object prototypes.
- return true;
- }
-
- MozjsGlobalEnvironment* global_environment =
- static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context));
- WrapperFactory* wrapper_factory = global_environment->wrapper_factory();
- if (!wrapper_factory->DoesObjectImplementInterface(
- object, base::GetTypeId<ConstructorWithArgumentsInterface>())) {
- MozjsExceptionState exception(context);
- exception.SetSimpleException(script::kDoesNotImplementInterface);
- return false;
- }
- MozjsExceptionState exception_state(context);
- JS::RootedValue result_value(context);
-
- WrapperPrivate* wrapper_private =
- WrapperPrivate::GetFromObject(context, object);
- ConstructorWithArgumentsInterface* impl =
- wrapper_private->wrappable<ConstructorWithArgumentsInterface>().get();
-
- if (!exception_state.is_exception_set()) {
- ToJSValue(context,
- impl->long_arg(),
- &result_value);
- }
- if (!exception_state.is_exception_set()) {
- vp.set(result_value);
- }
- return !exception_state.is_exception_set();
-}
-
-JSBool get_booleanArg(
- JSContext* context, JS::HandleObject object, JS::HandleId id,
- JS::MutableHandleValue vp) {
- const JSClass* proto_class =
- MozjsConstructorWithArgumentsInterface::PrototypeClass(context);
- if (proto_class == JS_GetClass(object)) {
- // Simply returns true if the object is this class's prototype object.
- // There is no need to return any value due to the object is not a platform
- // object. The execution reaches here when Object.getOwnPropertyDescriptor
- // gets called on native object prototypes.
- return true;
- }
-
- MozjsGlobalEnvironment* global_environment =
- static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context));
- WrapperFactory* wrapper_factory = global_environment->wrapper_factory();
- if (!wrapper_factory->DoesObjectImplementInterface(
- object, base::GetTypeId<ConstructorWithArgumentsInterface>())) {
- MozjsExceptionState exception(context);
- exception.SetSimpleException(script::kDoesNotImplementInterface);
- return false;
- }
- MozjsExceptionState exception_state(context);
- JS::RootedValue result_value(context);
-
- WrapperPrivate* wrapper_private =
- WrapperPrivate::GetFromObject(context, object);
- ConstructorWithArgumentsInterface* impl =
- wrapper_private->wrappable<ConstructorWithArgumentsInterface>().get();
-
- if (!exception_state.is_exception_set()) {
- ToJSValue(context,
- impl->boolean_arg(),
- &result_value);
- }
- if (!exception_state.is_exception_set()) {
- vp.set(result_value);
- }
- return !exception_state.is_exception_set();
-}
-
-JSBool get_stringArg(
- JSContext* context, JS::HandleObject object, JS::HandleId id,
- JS::MutableHandleValue vp) {
- const JSClass* proto_class =
- MozjsConstructorWithArgumentsInterface::PrototypeClass(context);
- if (proto_class == JS_GetClass(object)) {
- // Simply returns true if the object is this class's prototype object.
- // There is no need to return any value due to the object is not a platform
- // object. The execution reaches here when Object.getOwnPropertyDescriptor
- // gets called on native object prototypes.
- return true;
- }
-
- MozjsGlobalEnvironment* global_environment =
- static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context));
- WrapperFactory* wrapper_factory = global_environment->wrapper_factory();
- if (!wrapper_factory->DoesObjectImplementInterface(
- object, base::GetTypeId<ConstructorWithArgumentsInterface>())) {
- MozjsExceptionState exception(context);
- exception.SetSimpleException(script::kDoesNotImplementInterface);
- return false;
- }
- MozjsExceptionState exception_state(context);
- JS::RootedValue result_value(context);
-
- WrapperPrivate* wrapper_private =
- WrapperPrivate::GetFromObject(context, object);
- ConstructorWithArgumentsInterface* impl =
- wrapper_private->wrappable<ConstructorWithArgumentsInterface>().get();
-
- if (!exception_state.is_exception_set()) {
- ToJSValue(context,
- impl->string_arg(),
- &result_value);
- }
- if (!exception_state.is_exception_set()) {
- vp.set(result_value);
- }
- return !exception_state.is_exception_set();
-}
-
-
-const JSPropertySpec prototype_properties[] = {
- { // Readonly attribute
- "longArg", 0,
- JSPROP_SHARED | JSPROP_ENUMERATE | JSPROP_READONLY,
- JSOP_WRAPPER(&get_longArg),
- JSOP_NULLWRAPPER,
- },
- { // Readonly attribute
- "booleanArg", 0,
- JSPROP_SHARED | JSPROP_ENUMERATE | JSPROP_READONLY,
- JSOP_WRAPPER(&get_booleanArg),
- JSOP_NULLWRAPPER,
- },
- { // Readonly attribute
- "stringArg", 0,
- JSPROP_SHARED | JSPROP_ENUMERATE | JSPROP_READONLY,
- JSOP_WRAPPER(&get_stringArg),
- JSOP_NULLWRAPPER,
- },
- JS_PS_END
-};
-
-const JSFunctionSpec prototype_functions[] = {
- JS_FS_END
-};
-
-const JSPropertySpec interface_object_properties[] = {
- JS_PS_END
-};
-
-const JSFunctionSpec interface_object_functions[] = {
- JS_FS_END
-};
-
-const JSPropertySpec own_properties[] = {
- JS_PS_END
-};
-
-void InitializePrototypeAndInterfaceObject(
- InterfaceData* interface_data, JSContext* context,
- JS::HandleObject global_object) {
- DCHECK(!interface_data->prototype);
- DCHECK(!interface_data->interface_object);
- DCHECK(JS_IsGlobalObject(global_object));
-
- JS::RootedObject parent_prototype(
- context, JS_GetObjectPrototype(context, global_object));
- DCHECK(parent_prototype);
-
- // Create the Prototype object.
- interface_data->prototype = JS_NewObjectWithGivenProto(
- context, &interface_data->prototype_class_definition, parent_prototype,
- NULL);
- bool success = JS_DefineProperties(
- context, interface_data->prototype, prototype_properties);
- DCHECK(success);
- success = JS_DefineFunctions(
- context, interface_data->prototype, prototype_functions);
- DCHECK(success);
-
- JS::RootedObject function_prototype(
- context, JS_GetFunctionPrototype(context, global_object));
- DCHECK(function_prototype);
- // Create the Interface object.
- interface_data->interface_object = JS_NewObjectWithGivenProto(
- context, &interface_data->interface_object_class_definition,
- function_prototype, NULL);
-
- // Add the InterfaceObject.name property.
- JS::RootedObject rooted_interface_object(
- context, interface_data->interface_object);
- JS::RootedValue name_value(context);
- const char name[] =
- "ConstructorWithArgumentsInterface";
- name_value.setString(JS_NewStringCopyZ(context, name));
- success =
- JS_DefineProperty(context, rooted_interface_object, "name", name_value,
- JS_PropertyStub, JS_StrictPropertyStub,
- JSPROP_READONLY);
- DCHECK(success);
-
- // Add the InterfaceObject.length property. It is set to the length of the
- // shortest argument list of all overload constructors.
- JS::RootedValue length_value(context);
- length_value.setInt32(2);
- success =
- JS_DefineProperty(context, rooted_interface_object, "length",
- length_value, JS_PropertyStub, JS_StrictPropertyStub,
- JSPROP_READONLY);
- DCHECK(success);
-
- // Define interface object properties (including constants).
- success = JS_DefineProperties(context, rooted_interface_object,
- interface_object_properties);
- DCHECK(success);
- // Define interface object functions (static).
- success = JS_DefineFunctions(context, rooted_interface_object,
- interface_object_functions);
- DCHECK(success);
-
-
- // Set the Prototype.constructor and Constructor.prototype properties.
- DCHECK(interface_data->interface_object);
- DCHECK(interface_data->prototype);
- JS::RootedObject rooted_prototype(context, interface_data->prototype);
- success = JS_LinkConstructorAndPrototype(
- context,
- rooted_interface_object,
- rooted_prototype);
- DCHECK(success);
-}
-
-InterfaceData* GetInterfaceData(JSContext* context) {
- MozjsGlobalEnvironment* global_environment =
- static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context));
- // Use the address of the properties definition for this interface as a
- // unique key for looking up the InterfaceData for this interface.
- intptr_t key = reinterpret_cast<intptr_t>(&own_properties);
- InterfaceData* interface_data = global_environment->GetInterfaceData(key);
- if (!interface_data) {
- interface_data = CreateCachedInterfaceData();
- DCHECK(interface_data);
- global_environment->CacheInterfaceData(key, interface_data);
- DCHECK_EQ(interface_data, global_environment->GetInterfaceData(key));
- }
- return interface_data;
-}
-
-} // namespace
-
-// static
-JSObject* MozjsConstructorWithArgumentsInterface::CreateProxy(
- JSContext* context, const scoped_refptr<Wrappable>& wrappable) {
- DCHECK(MozjsGlobalEnvironment::GetFromContext(context));
- JS::RootedObject global_object(
- context,
- MozjsGlobalEnvironment::GetFromContext(context)->global_object());
- DCHECK(global_object);
-
- InterfaceData* interface_data = GetInterfaceData(context);
- JS::RootedObject prototype(context, GetPrototype(context, global_object));
- DCHECK(prototype);
- JS::RootedObject new_object(context, JS_NewObjectWithGivenProto(
- context, &interface_data->instance_class_definition, prototype, NULL));
- DCHECK(new_object);
- JS::RootedObject proxy(context,
- ProxyHandler::NewProxy(context, new_object, prototype, NULL,
- proxy_handler.Pointer()));
- WrapperPrivate::AddPrivateData(context, proxy, wrappable);
- return proxy;
-}
-
-//static
-const JSClass* MozjsConstructorWithArgumentsInterface::PrototypeClass(
- JSContext* context) {
- DCHECK(MozjsGlobalEnvironment::GetFromContext(context));
- JS::RootedObject global_object(
- context,
- MozjsGlobalEnvironment::GetFromContext(context)->global_object());
- DCHECK(global_object);
-
- JS::RootedObject prototype(context, GetPrototype(context, global_object));
- JSClass* proto_class = JS_GetClass(*prototype.address());
- return proto_class;
-}
-
-// static
-JSObject* MozjsConstructorWithArgumentsInterface::GetPrototype(
- JSContext* context, JS::HandleObject global_object) {
- DCHECK(JS_IsGlobalObject(global_object));
-
- InterfaceData* interface_data = GetInterfaceData(context);
- if (!interface_data->prototype) {
- // Create new prototype that has all the props and methods
- InitializePrototypeAndInterfaceObject(
- interface_data, context, global_object);
- }
- DCHECK(interface_data->prototype);
- return interface_data->prototype;
-}
-
-// static
-JSObject* MozjsConstructorWithArgumentsInterface::GetInterfaceObject(
- JSContext* context, JS::HandleObject global_object) {
- DCHECK(JS_IsGlobalObject(global_object));
-
- InterfaceData* interface_data = GetInterfaceData(context);
- if (!interface_data->interface_object) {
- InitializePrototypeAndInterfaceObject(
- interface_data, context, global_object);
- }
- DCHECK(interface_data->interface_object);
- return interface_data->interface_object;
-}
-
-
-namespace {
-JSBool Constructor(JSContext* context, unsigned int argc, JS::Value* vp) {
- MozjsExceptionState exception_state(context);
- JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
- const size_t kMinArguments = 2;
- if (args.length() < kMinArguments) {
- exception_state.SetSimpleException(script::kInvalidNumberOfArguments);
- return false;
- }
- // Non-optional arguments
- TypeTraits<int32_t >::ConversionType arg1;
- TypeTraits<bool >::ConversionType arg2;
- // Optional arguments with default values
- TypeTraits<std::string >::ConversionType default_arg =
- "default";
-
- DCHECK_LT(0, args.length());
- JS::RootedValue non_optional_value0(
- context, args[0]);
- FromJSValue(context,
- non_optional_value0,
- kNoConversionFlags,
- &exception_state, &arg1);
- if (exception_state.is_exception_set()) {
- return false;
- }
-
- DCHECK_LT(1, args.length());
- JS::RootedValue non_optional_value1(
- context, args[1]);
- FromJSValue(context,
- non_optional_value1,
- kNoConversionFlags,
- &exception_state, &arg2);
- if (exception_state.is_exception_set()) {
- return false;
- }
- size_t num_set_arguments = 3;
- if (args.length() > 2) {
- JS::RootedValue optional_value0(
- context, args[2]);
- FromJSValue(context,
- optional_value0,
- kNoConversionFlags,
- &exception_state,
- &default_arg);
- if (exception_state.is_exception_set()) {
- return false;
- }
- }
-
- scoped_refptr<ConstructorWithArgumentsInterface> new_object =
- new ConstructorWithArgumentsInterface(arg1, arg2, default_arg);
- JS::RootedValue result_value(context);
- ToJSValue(context, new_object, &result_value);
- DCHECK(result_value.isObject());
- JS::RootedObject result_object(context, JSVAL_TO_OBJECT(result_value));
- args.rval().setObject(*result_object);
- return true;
-}
-} // namespace
-
-
-} // namespace testing
-} // namespace bindings
-} // namespace cobalt
diff --git a/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_constructor_with_arguments_interface.h b/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_constructor_with_arguments_interface.h
deleted file mode 100644
index 058d6c4..0000000
--- a/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_constructor_with_arguments_interface.h
+++ /dev/null
@@ -1,52 +0,0 @@
-// Copyright 2017 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/mozjs/templates/interface.h.template
-
-#ifndef MozjsConstructorWithArgumentsInterface_h
-#define MozjsConstructorWithArgumentsInterface_h
-
-#include "base/hash_tables.h"
-#include "base/lazy_instance.h"
-#include "base/memory/ref_counted.h"
-#include "base/threading/thread_checker.h"
-#include "cobalt/base/polymorphic_downcast.h"
-#include "cobalt/script/wrappable.h"
-#include "cobalt/bindings/testing/constructor_with_arguments_interface.h"
-
-#include "third_party/mozjs/js/src/jsapi.h"
-
-namespace cobalt {
-namespace bindings {
-namespace testing {
-
-class MozjsConstructorWithArgumentsInterface {
- public:
- static JSObject* CreateProxy(JSContext* context,
- const scoped_refptr<script::Wrappable>& wrappable);
- static const JSClass* PrototypeClass(JSContext* context);
- static JSObject* GetPrototype(JSContext* context,
- JS::HandleObject global_object);
- static JSObject* GetInterfaceObject(JSContext* context,
- JS::HandleObject global_object);
-};
-
-} // namespace testing
-} // namespace bindings
-} // namespace cobalt
-
-#endif // MozjsConstructorWithArgumentsInterface_h
diff --git a/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_derived_dictionary.cc b/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_derived_dictionary.cc
deleted file mode 100644
index 6c23574..0000000
--- a/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_derived_dictionary.cc
+++ /dev/null
@@ -1,103 +0,0 @@
-/*
- * Copyright 2017 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/mozjs/templates/dictionary-conversion.cc.template
-
-#include "mozjs_gen_type_conversion.h"
-
-#include "cobalt/bindings/testing/derived_dictionary.h"
-
-#include "cobalt/script/exception_state.h"
-#include "third_party/mozjs/js/src/jsapi.h"
-#include "cobalt/bindings/testing/test_dictionary.h"
-
-using cobalt::bindings::testing::DerivedDictionary;
-using cobalt::bindings::testing::TestDictionary;
-
-namespace cobalt {
-namespace script {
-namespace mozjs {
-
-void ToJSValue(
- JSContext* context,
- const DerivedDictionary& in_dictionary,
- JS::MutableHandleValue out_value) {
- // Create a new object that will hold the dictionary values.
- JS::RootedObject dictionary_object(
- context, JS_NewObject(context, NULL, NULL, NULL));
- const int kPropertyAttributes = JSPROP_ENUMERATE;
- if (in_dictionary.has_additional_member()) {
- JS::RootedValue member_value(context);
- ToJSValue(context, in_dictionary.additional_member(), &member_value);
- if (!JS_DefineProperty(context, dictionary_object,
- "additionalMember",
- member_value, NULL, NULL, kPropertyAttributes)) {
- // Some internal error occurred.
- NOTREACHED();
- return;
- }
- }
- out_value.set(OBJECT_TO_JSVAL(dictionary_object));
-}
-
-void FromJSValue(JSContext* context, JS::HandleValue value,
- int conversion_flags, ExceptionState* exception_state,
- DerivedDictionary* out_dictionary) {
- DCHECK_EQ(0, conversion_flags) << "Unexpected conversion flags.";
- FromJSValue(context, value, conversion_flags, exception_state,
- static_cast<cobalt::bindings::testing::TestDictionary*>(out_dictionary));
- // https://heycam.github.io/webidl/#es-dictionary
-
- if (value.isUndefined() || value.isNull()) {
- // The default constructor will assign appropriate values to dictionary
- // members with default values and leave the others unset.
- *out_dictionary = DerivedDictionary();
- return;
- }
- if (!value.isObject()) {
- // 1. If Type(V) is not Undefined, Null or Object, then throw a TypeError.
- exception_state->SetSimpleException(kNotObjectType);
- return;
- }
- JS::RootedObject dictionary_object(context, JSVAL_TO_OBJECT(value));
- JS::RootedValue additional_member(context);
- if (!JS_GetProperty(context, dictionary_object,
- "additionalMember",
- additional_member.address())) {
- exception_state->SetSimpleException(kSimpleError);
- return;
- }
- if (!additional_member.isUndefined()) {
- bool converted_value;
- FromJSValue(context,
- additional_member,
- kNoConversionFlags,
- exception_state,
- &converted_value);
- if (context->isExceptionPending()) {
- return;
- }
- out_dictionary->set_additional_member(converted_value);
- }
-}
-
-} // namespace mozjs
-} // namespace script
-} // namespace cobalt
-
diff --git a/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_derived_getter_setter_interface.cc b/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_derived_getter_setter_interface.cc
deleted file mode 100644
index ed56d9f..0000000
--- a/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_derived_getter_setter_interface.cc
+++ /dev/null
@@ -1,904 +0,0 @@
-// Copyright 2017 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/mozjs/templates/interface.cc.template
-
-#include "cobalt/bindings/testing/mozjs_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/opaque_handle.h"
-#include "cobalt/script/script_value.h"
-#include "cobalt/bindings/testing/mozjs_named_indexed_getter_interface.h"
-#include "cobalt/bindings/testing/named_indexed_getter_interface.h"
-
-#include "mozjs_gen_type_conversion.h"
-
-#include "base/lazy_instance.h"
-#include "cobalt/script/exception_state.h"
-#include "cobalt/script/mozjs/callback_function_conversion.h"
-#include "cobalt/script/mozjs/conversion_helpers.h"
-#include "cobalt/script/mozjs/mozjs_callback_function.h"
-#include "cobalt/script/mozjs/mozjs_exception_state.h"
-#include "cobalt/script/mozjs/mozjs_global_environment.h"
-#include "cobalt/script/mozjs/mozjs_object_handle.h"
-#include "cobalt/script/mozjs/mozjs_property_enumerator.h"
-#include "cobalt/script/mozjs/mozjs_user_object_holder.h"
-#include "cobalt/script/mozjs/mozjs_value_handle.h"
-#include "cobalt/script/mozjs/native_promise.h"
-#include "cobalt/script/mozjs/proxy_handler.h"
-#include "cobalt/script/mozjs/type_traits.h"
-#include "cobalt/script/mozjs/wrapper_factory.h"
-#include "cobalt/script/mozjs/wrapper_private.h"
-#include "cobalt/script/property_enumerator.h"
-#include "cobalt/script/sequence.h"
-#include "third_party/mozjs/js/src/jsapi.h"
-#include "third_party/mozjs/js/src/jsfriendapi.h"
-
-namespace {
-using cobalt::bindings::testing::DerivedGetterSetterInterface;
-using cobalt::bindings::testing::MozjsDerivedGetterSetterInterface;
-using cobalt::bindings::testing::MozjsNamedIndexedGetterInterface;
-using cobalt::bindings::testing::NamedIndexedGetterInterface;
-using cobalt::script::CallbackInterfaceTraits;
-using cobalt::script::GlobalEnvironment;
-using cobalt::script::OpaqueHandle;
-using cobalt::script::OpaqueHandleHolder;
-using cobalt::script::ScriptValue;
-using cobalt::script::ValueHandle;
-using cobalt::script::Wrappable;
-
-using cobalt::script::CallbackFunction;
-using cobalt::script::CallbackInterfaceTraits;
-using cobalt::script::ExceptionState;
-using cobalt::script::Wrappable;
-using cobalt::script::mozjs::FromJSValue;
-using cobalt::script::mozjs::InterfaceData;
-using cobalt::script::mozjs::MozjsCallbackFunction;
-using cobalt::script::mozjs::MozjsExceptionState;
-using cobalt::script::mozjs::MozjsGlobalEnvironment;
-using cobalt::script::mozjs::MozjsPropertyEnumerator;
-using cobalt::script::mozjs::MozjsUserObjectHolder;
-using cobalt::script::mozjs::ProxyHandler;
-using cobalt::script::mozjs::ToJSValue;
-using cobalt::script::mozjs::TypeTraits;
-using cobalt::script::mozjs::WrapperFactory;
-using cobalt::script::mozjs::WrapperPrivate;
-using cobalt::script::mozjs::kConversionFlagClamped;
-using cobalt::script::mozjs::kConversionFlagNullable;
-using cobalt::script::mozjs::kConversionFlagRestricted;
-using cobalt::script::mozjs::kConversionFlagTreatNullAsEmptyString;
-using cobalt::script::mozjs::kConversionFlagTreatUndefinedAsEmptyString;
-using cobalt::script::mozjs::kNoConversionFlags;
-} // namespace
-
-namespace cobalt {
-namespace bindings {
-namespace testing {
-
-namespace {
-
-bool IsSupportedNamedProperty(JSContext* context, JS::HandleObject object,
- const std::string& property_name) {
- WrapperPrivate* wrapper_private =
- WrapperPrivate::GetFromObject(context, object);
- DerivedGetterSetterInterface* impl =
- wrapper_private->wrappable<DerivedGetterSetterInterface>().get();
- return impl->CanQueryNamedProperty(property_name);
-}
-
-void EnumerateSupportedNames(JSContext* context, JS::HandleObject object,
- JS::AutoIdVector* properties) {
- WrapperPrivate* wrapper_private =
- WrapperPrivate::GetFromObject(context, object);
- DerivedGetterSetterInterface* impl =
- wrapper_private->wrappable<DerivedGetterSetterInterface>().get();
- MozjsPropertyEnumerator enumerator(context, properties);
- impl->EnumerateNamedProperties(&enumerator);
-}
-
-JSBool GetNamedProperty(
- JSContext* context, JS::HandleObject object, JS::HandleId id,
- JS::MutableHandleValue vp) {
- JS::RootedValue id_value(context);
- if (!JS_IdToValue(context, id, id_value.address())) {
- NOTREACHED();
- return false;
- }
-
- MozjsExceptionState exception_state(context);
- JS::RootedValue result_value(context);
-
- WrapperPrivate* wrapper_private =
- WrapperPrivate::GetFromObject(context, object);
- DerivedGetterSetterInterface* impl =
- wrapper_private->wrappable<DerivedGetterSetterInterface>().get();
- std::string property_name;
- FromJSValue(context, id_value, kNoConversionFlags, &exception_state,
- &property_name);
- if (exception_state.is_exception_set()) {
- // The ID should be an integer or a string, so we shouldn't have any
- // exceptions converting to string.
- NOTREACHED();
- return false;
- }
-
- if (!exception_state.is_exception_set()) {
- ToJSValue(context,
- impl->AnonymousNamedGetter(property_name),
- &result_value);
- }
- if (!exception_state.is_exception_set()) {
- vp.set(result_value);
- }
- return !exception_state.is_exception_set();
-}
-
-JSBool SetNamedProperty(
- JSContext* context, JS::HandleObject object, JS::HandleId id,
- JSBool strict, JS::MutableHandleValue vp) {
- JS::RootedValue id_value(context);
- if (!JS_IdToValue(context, id, id_value.address())) {
- NOTREACHED();
- return false;
- }
- MozjsExceptionState exception_state(context);
- JS::RootedValue result_value(context);
-
- WrapperPrivate* wrapper_private =
- WrapperPrivate::GetFromObject(context, object);
- DerivedGetterSetterInterface* impl =
- wrapper_private->wrappable<DerivedGetterSetterInterface>().get();
- std::string property_name;
- FromJSValue(context, id_value, kNoConversionFlags, &exception_state,
- &property_name);
- if (exception_state.is_exception_set()) {
- // The ID should be an integer or a string, so we shouldn't have any
- // exceptions converting to string.
- NOTREACHED();
- return false;
- }
- TypeTraits<std::string >::ConversionType value;
- FromJSValue(context, vp, kNoConversionFlags,
- &exception_state, &value);
- if (exception_state.is_exception_set()) {
- return false;
- }
-
- impl->AnonymousNamedSetter(property_name, value);
- result_value.set(JS::UndefinedHandleValue);
- return !exception_state.is_exception_set();
-}
-
-bool IsSupportedIndexProperty(JSContext* context, JS::HandleObject object,
- uint32_t index) {
- WrapperPrivate* wrapper_private =
- WrapperPrivate::GetFromObject(context, object);
- DerivedGetterSetterInterface* impl =
- wrapper_private->wrappable<DerivedGetterSetterInterface>().get();
- return index < impl->length();
-}
-
-void EnumerateSupportedIndexes(JSContext* context, JS::HandleObject object,
- JS::AutoIdVector* properties) {
- WrapperPrivate* wrapper_private =
- WrapperPrivate::GetFromObject(context, object);
- DerivedGetterSetterInterface* impl =
- wrapper_private->wrappable<DerivedGetterSetterInterface>().get();
- const uint32_t kNumIndexedProperties = impl->length();
- for (uint32_t i = 0; i < kNumIndexedProperties; ++i) {
- properties->append(INT_TO_JSID(i));
- }
-}
-
-JSBool GetIndexedProperty(
- JSContext* context, JS::HandleObject object, JS::HandleId id,
- JS::MutableHandleValue vp) {
- JS::RootedValue id_value(context);
- if (!JS_IdToValue(context, id, id_value.address())) {
- NOTREACHED();
- return false;
- }
- MozjsExceptionState exception_state(context);
- JS::RootedValue result_value(context);
-
- WrapperPrivate* wrapper_private =
- WrapperPrivate::GetFromObject(context, object);
- DerivedGetterSetterInterface* impl =
- wrapper_private->wrappable<DerivedGetterSetterInterface>().get();
- uint32_t index;
- FromJSValue(context, id_value, kNoConversionFlags, &exception_state, &index);
- if (exception_state.is_exception_set()) {
- // The ID should be an integer or a string, so we shouldn't have any
- // exceptions converting to string.
- NOTREACHED();
- return false;
- }
-
- if (!exception_state.is_exception_set()) {
- ToJSValue(context,
- impl->DerivedIndexedGetter(index),
- &result_value);
- }
- if (!exception_state.is_exception_set()) {
- vp.set(result_value);
- }
- return !exception_state.is_exception_set();
-}
-
-JSBool SetIndexedProperty(
- JSContext* context, JS::HandleObject object, JS::HandleId id,
- JSBool strict, JS::MutableHandleValue vp) {
- JS::RootedValue id_value(context);
- if (!JS_IdToValue(context, id, id_value.address())) {
- NOTREACHED();
- return false;
- }
- MozjsExceptionState exception_state(context);
- JS::RootedValue result_value(context);
-
- WrapperPrivate* wrapper_private =
- WrapperPrivate::GetFromObject(context, object);
- DerivedGetterSetterInterface* impl =
- wrapper_private->wrappable<DerivedGetterSetterInterface>().get();
- uint32_t index;
- FromJSValue(context, id_value, kNoConversionFlags, &exception_state, &index);
- if(exception_state.is_exception_set()) {
- // The ID should be an integer or a string, so we shouldn't have any
- // exceptions converting to string.
- NOTREACHED();
- return false;
- }
- TypeTraits<uint32_t >::ConversionType value;
- FromJSValue(context, vp, kNoConversionFlags,
- &exception_state, &value);
- if (exception_state.is_exception_set()) {
- return false;
- }
-
- impl->DerivedIndexedSetter(index, value);
- result_value.set(JS::UndefinedHandleValue);
- return !exception_state.is_exception_set();
-}
-
-class MozjsDerivedGetterSetterInterfaceHandler : public ProxyHandler {
- public:
- MozjsDerivedGetterSetterInterfaceHandler()
- : ProxyHandler(indexed_property_hooks, named_property_hooks) {}
-
- private:
- static NamedPropertyHooks named_property_hooks;
- static IndexedPropertyHooks indexed_property_hooks;
-};
-
-ProxyHandler::NamedPropertyHooks
-MozjsDerivedGetterSetterInterfaceHandler::named_property_hooks = {
- IsSupportedNamedProperty,
- EnumerateSupportedNames,
- GetNamedProperty,
- SetNamedProperty,
- NULL,
-};
-ProxyHandler::IndexedPropertyHooks
-MozjsDerivedGetterSetterInterfaceHandler::indexed_property_hooks = {
- IsSupportedIndexProperty,
- EnumerateSupportedIndexes,
- GetIndexedProperty,
- SetIndexedProperty,
- NULL,
-};
-
-static base::LazyInstance<MozjsDerivedGetterSetterInterfaceHandler>
- proxy_handler;
-
-JSBool HasInstance(JSContext *context, JS::HandleObject type,
- JS::MutableHandleValue vp, JSBool *success) {
- JS::RootedObject global_object(
- context, JS_GetGlobalForObject(context, type));
- DCHECK(global_object);
-
- JS::RootedObject prototype(
- context, MozjsDerivedGetterSetterInterface::GetPrototype(context, global_object));
-
- // |IsDelegate| walks the prototype chain of an object returning true if
- // .prototype is found.
- bool is_delegate;
- if (!IsDelegate(context, prototype, vp, &is_delegate)) {
- *success = false;
- return false;
- }
-
- *success = is_delegate;
- return true;
-}
-
-InterfaceData* CreateCachedInterfaceData() {
- InterfaceData* interface_data = new InterfaceData();
- memset(&interface_data->instance_class_definition, 0,
- sizeof(interface_data->instance_class_definition));
- memset(&interface_data->prototype_class_definition, 0,
- sizeof(interface_data->prototype_class_definition));
- memset(&interface_data->interface_object_class_definition, 0,
- sizeof(interface_data->interface_object_class_definition));
-
- JSClass* instance_class = &interface_data->instance_class_definition;
- const int kGlobalFlags = 0;
- instance_class->name = "DerivedGetterSetterInterface";
- instance_class->flags = kGlobalFlags | JSCLASS_HAS_PRIVATE;
- instance_class->addProperty = JS_PropertyStub;
- instance_class->delProperty = JS_DeletePropertyStub;
- instance_class->getProperty = JS_PropertyStub;
- instance_class->setProperty = JS_StrictPropertyStub;
- instance_class->enumerate = JS_EnumerateStub;
- instance_class->resolve = JS_ResolveStub;
- instance_class->convert = JS_ConvertStub;
- // Function to be called before on object of this class is garbage collected.
- instance_class->finalize = &WrapperPrivate::Finalizer;
- // Called to trace objects that can be referenced from this object.
- instance_class->trace = &WrapperPrivate::Trace;
-
- JSClass* prototype_class = &interface_data->prototype_class_definition;
- prototype_class->name = "DerivedGetterSetterInterfacePrototype";
- prototype_class->flags = 0;
- prototype_class->addProperty = JS_PropertyStub;
- prototype_class->delProperty = JS_DeletePropertyStub;
- prototype_class->getProperty = JS_PropertyStub;
- prototype_class->setProperty = JS_StrictPropertyStub;
- prototype_class->enumerate = JS_EnumerateStub;
- prototype_class->resolve = JS_ResolveStub;
- prototype_class->convert = JS_ConvertStub;
-
- JSClass* interface_object_class =
- &interface_data->interface_object_class_definition;
- interface_object_class->name = "DerivedGetterSetterInterfaceConstructor";
- interface_object_class->flags = 0;
- interface_object_class->addProperty = JS_PropertyStub;
- interface_object_class->delProperty = JS_DeletePropertyStub;
- interface_object_class->getProperty = JS_PropertyStub;
- interface_object_class->setProperty = JS_StrictPropertyStub;
- interface_object_class->enumerate = JS_EnumerateStub;
- interface_object_class->resolve = JS_ResolveStub;
- interface_object_class->convert = JS_ConvertStub;
- interface_object_class->hasInstance = &HasInstance;
- return interface_data;
-}
-
-JSBool get_length(
- JSContext* context, JS::HandleObject object, JS::HandleId id,
- JS::MutableHandleValue vp) {
- const JSClass* proto_class =
- MozjsDerivedGetterSetterInterface::PrototypeClass(context);
- if (proto_class == JS_GetClass(object)) {
- // Simply returns true if the object is this class's prototype object.
- // There is no need to return any value due to the object is not a platform
- // object. The execution reaches here when Object.getOwnPropertyDescriptor
- // gets called on native object prototypes.
- return true;
- }
-
- MozjsGlobalEnvironment* global_environment =
- static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context));
- WrapperFactory* wrapper_factory = global_environment->wrapper_factory();
- if (!wrapper_factory->DoesObjectImplementInterface(
- object, base::GetTypeId<DerivedGetterSetterInterface>())) {
- MozjsExceptionState exception(context);
- exception.SetSimpleException(script::kDoesNotImplementInterface);
- return false;
- }
- MozjsExceptionState exception_state(context);
- JS::RootedValue result_value(context);
-
- WrapperPrivate* wrapper_private =
- WrapperPrivate::GetFromObject(context, object);
- DerivedGetterSetterInterface* impl =
- wrapper_private->wrappable<DerivedGetterSetterInterface>().get();
-
- if (!exception_state.is_exception_set()) {
- ToJSValue(context,
- impl->length(),
- &result_value);
- }
- if (!exception_state.is_exception_set()) {
- vp.set(result_value);
- }
- return !exception_state.is_exception_set();
-}
-
-JSBool get_propertyOnDerivedClass(
- JSContext* context, JS::HandleObject object, JS::HandleId id,
- JS::MutableHandleValue vp) {
- const JSClass* proto_class =
- MozjsDerivedGetterSetterInterface::PrototypeClass(context);
- if (proto_class == JS_GetClass(object)) {
- // Simply returns true if the object is this class's prototype object.
- // There is no need to return any value due to the object is not a platform
- // object. The execution reaches here when Object.getOwnPropertyDescriptor
- // gets called on native object prototypes.
- return true;
- }
-
- MozjsGlobalEnvironment* global_environment =
- static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context));
- WrapperFactory* wrapper_factory = global_environment->wrapper_factory();
- if (!wrapper_factory->DoesObjectImplementInterface(
- object, base::GetTypeId<DerivedGetterSetterInterface>())) {
- MozjsExceptionState exception(context);
- exception.SetSimpleException(script::kDoesNotImplementInterface);
- return false;
- }
- MozjsExceptionState exception_state(context);
- JS::RootedValue result_value(context);
-
- WrapperPrivate* wrapper_private =
- WrapperPrivate::GetFromObject(context, object);
- DerivedGetterSetterInterface* impl =
- wrapper_private->wrappable<DerivedGetterSetterInterface>().get();
-
- if (!exception_state.is_exception_set()) {
- ToJSValue(context,
- impl->property_on_derived_class(),
- &result_value);
- }
- if (!exception_state.is_exception_set()) {
- vp.set(result_value);
- }
- return !exception_state.is_exception_set();
-}
-
-JSBool set_propertyOnDerivedClass(
- JSContext* context, JS::HandleObject object, JS::HandleId id,
- JSBool strict, JS::MutableHandleValue vp) {
- const JSClass* proto_class =
- MozjsDerivedGetterSetterInterface::PrototypeClass(context);
- if (proto_class == JS_GetClass(object)) {
- // Simply returns true if the object is this class's prototype object.
- // There is no need to return any value due to the object is not a platform
- // object. The execution reaches here when Object.getOwnPropertyDescriptor
- // gets called on native object prototypes.
- return true;
- }
-
- MozjsGlobalEnvironment* global_environment =
- static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context));
- WrapperFactory* wrapper_factory = global_environment->wrapper_factory();
- if (!wrapper_factory->DoesObjectImplementInterface(
- object, base::GetTypeId<DerivedGetterSetterInterface>())) {
- MozjsExceptionState exception(context);
- exception.SetSimpleException(script::kDoesNotImplementInterface);
- return false;
- }
- MozjsExceptionState exception_state(context);
- JS::RootedValue result_value(context);
-
- WrapperPrivate* wrapper_private =
- WrapperPrivate::GetFromObject(context, object);
- DerivedGetterSetterInterface* impl =
- wrapper_private->wrappable<DerivedGetterSetterInterface>().get();
- TypeTraits<bool >::ConversionType value;
- FromJSValue(context, vp, kNoConversionFlags, &exception_state,
- &value);
- if (exception_state.is_exception_set()) {
- return false;
- }
-
- impl->set_property_on_derived_class(value);
- result_value.set(JS::UndefinedHandleValue);
- return !exception_state.is_exception_set();
-}
-
-JSBool fcn_derivedIndexedGetter(
- JSContext* context, uint32_t argc, JS::Value *vp) {
- JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
- // Compute the 'this' value.
- JS::RootedValue this_value(context, JS_ComputeThis(context, vp));
- // 'this' should be an object.
- JS::RootedObject object(context);
- if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) {
- return false;
- }
- if (!JS_ValueToObject(context, this_value, object.address())) {
- NOTREACHED();
- return false;
- }
- const JSClass* proto_class =
- MozjsDerivedGetterSetterInterface::PrototypeClass(context);
- if (proto_class == JS_GetClass(object)) {
- // Simply returns true if the object is this class's prototype object.
- // There is no need to return any value due to the object is not a platform
- // object. The execution reaches here when Object.getOwnPropertyDescriptor
- // gets called on native object prototypes.
- return true;
- }
-
- MozjsGlobalEnvironment* global_environment =
- static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context));
- WrapperFactory* wrapper_factory = global_environment->wrapper_factory();
- if (!wrapper_factory->DoesObjectImplementInterface(
- object, base::GetTypeId<DerivedGetterSetterInterface>())) {
- MozjsExceptionState exception(context);
- exception.SetSimpleException(script::kDoesNotImplementInterface);
- return false;
- }
- MozjsExceptionState exception_state(context);
- JS::RootedValue result_value(context);
-
- WrapperPrivate* wrapper_private =
- WrapperPrivate::GetFromObject(context, object);
- DerivedGetterSetterInterface* impl =
- wrapper_private->wrappable<DerivedGetterSetterInterface>().get();
- const size_t kMinArguments = 1;
- if (args.length() < kMinArguments) {
- exception_state.SetSimpleException(script::kInvalidNumberOfArguments);
- return false;
- }
- // Non-optional arguments
- TypeTraits<uint32_t >::ConversionType index;
-
- DCHECK_LT(0, args.length());
- JS::RootedValue non_optional_value0(
- context, args[0]);
- FromJSValue(context,
- non_optional_value0,
- kNoConversionFlags,
- &exception_state, &index);
- if (exception_state.is_exception_set()) {
- return false;
- }
-
- if (!exception_state.is_exception_set()) {
- ToJSValue(context,
- impl->DerivedIndexedGetter(index),
- &result_value);
- }
- if (!exception_state.is_exception_set()) {
- args.rval().set(result_value);
- }
- return !exception_state.is_exception_set();
-}
-
-JSBool fcn_derivedIndexedSetter(
- JSContext* context, uint32_t argc, JS::Value *vp) {
- JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
- // Compute the 'this' value.
- JS::RootedValue this_value(context, JS_ComputeThis(context, vp));
- // 'this' should be an object.
- JS::RootedObject object(context);
- if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) {
- return false;
- }
- if (!JS_ValueToObject(context, this_value, object.address())) {
- NOTREACHED();
- return false;
- }
- const JSClass* proto_class =
- MozjsDerivedGetterSetterInterface::PrototypeClass(context);
- if (proto_class == JS_GetClass(object)) {
- // Simply returns true if the object is this class's prototype object.
- // There is no need to return any value due to the object is not a platform
- // object. The execution reaches here when Object.getOwnPropertyDescriptor
- // gets called on native object prototypes.
- return true;
- }
-
- MozjsGlobalEnvironment* global_environment =
- static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context));
- WrapperFactory* wrapper_factory = global_environment->wrapper_factory();
- if (!wrapper_factory->DoesObjectImplementInterface(
- object, base::GetTypeId<DerivedGetterSetterInterface>())) {
- MozjsExceptionState exception(context);
- exception.SetSimpleException(script::kDoesNotImplementInterface);
- return false;
- }
- MozjsExceptionState exception_state(context);
- JS::RootedValue result_value(context);
-
- WrapperPrivate* wrapper_private =
- WrapperPrivate::GetFromObject(context, object);
- DerivedGetterSetterInterface* impl =
- wrapper_private->wrappable<DerivedGetterSetterInterface>().get();
- const size_t kMinArguments = 2;
- if (args.length() < kMinArguments) {
- exception_state.SetSimpleException(script::kInvalidNumberOfArguments);
- return false;
- }
- // Non-optional arguments
- TypeTraits<uint32_t >::ConversionType index;
- TypeTraits<uint32_t >::ConversionType value;
-
- DCHECK_LT(0, args.length());
- JS::RootedValue non_optional_value0(
- context, args[0]);
- FromJSValue(context,
- non_optional_value0,
- kNoConversionFlags,
- &exception_state, &index);
- if (exception_state.is_exception_set()) {
- return false;
- }
-
- DCHECK_LT(1, args.length());
- JS::RootedValue non_optional_value1(
- context, args[1]);
- FromJSValue(context,
- non_optional_value1,
- kNoConversionFlags,
- &exception_state, &value);
- if (exception_state.is_exception_set()) {
- return false;
- }
-
- impl->DerivedIndexedSetter(index, value);
- result_value.set(JS::UndefinedHandleValue);
- return !exception_state.is_exception_set();
-}
-
-JSBool fcn_operationOnDerivedClass(
- JSContext* context, uint32_t argc, JS::Value *vp) {
- JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
- // Compute the 'this' value.
- JS::RootedValue this_value(context, JS_ComputeThis(context, vp));
- // 'this' should be an object.
- JS::RootedObject object(context);
- if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) {
- return false;
- }
- if (!JS_ValueToObject(context, this_value, object.address())) {
- NOTREACHED();
- return false;
- }
- const JSClass* proto_class =
- MozjsDerivedGetterSetterInterface::PrototypeClass(context);
- if (proto_class == JS_GetClass(object)) {
- // Simply returns true if the object is this class's prototype object.
- // There is no need to return any value due to the object is not a platform
- // object. The execution reaches here when Object.getOwnPropertyDescriptor
- // gets called on native object prototypes.
- return true;
- }
-
- MozjsGlobalEnvironment* global_environment =
- static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context));
- WrapperFactory* wrapper_factory = global_environment->wrapper_factory();
- if (!wrapper_factory->DoesObjectImplementInterface(
- object, base::GetTypeId<DerivedGetterSetterInterface>())) {
- MozjsExceptionState exception(context);
- exception.SetSimpleException(script::kDoesNotImplementInterface);
- return false;
- }
- MozjsExceptionState exception_state(context);
- JS::RootedValue result_value(context);
-
- WrapperPrivate* wrapper_private =
- WrapperPrivate::GetFromObject(context, object);
- DerivedGetterSetterInterface* impl =
- wrapper_private->wrappable<DerivedGetterSetterInterface>().get();
-
- impl->OperationOnDerivedClass();
- result_value.set(JS::UndefinedHandleValue);
- return !exception_state.is_exception_set();
-}
-
-
-const JSPropertySpec prototype_properties[] = {
- { // Readonly attribute
- "length", 0,
- JSPROP_SHARED | JSPROP_ENUMERATE | JSPROP_READONLY,
- JSOP_WRAPPER(&get_length),
- JSOP_NULLWRAPPER,
- },
- { // Read/Write property
- "propertyOnDerivedClass", 0,
- JSPROP_SHARED | JSPROP_ENUMERATE,
- JSOP_WRAPPER(&get_propertyOnDerivedClass),
- JSOP_WRAPPER(&set_propertyOnDerivedClass),
- },
- JS_PS_END
-};
-
-const JSFunctionSpec prototype_functions[] = {
- {
- "derivedIndexedGetter",
- JSOP_WRAPPER(&fcn_derivedIndexedGetter),
- 1,
- JSPROP_ENUMERATE,
- NULL,
- },
- {
- "derivedIndexedSetter",
- JSOP_WRAPPER(&fcn_derivedIndexedSetter),
- 2,
- JSPROP_ENUMERATE,
- NULL,
- },
- {
- "operationOnDerivedClass",
- JSOP_WRAPPER(&fcn_operationOnDerivedClass),
- 0,
- JSPROP_ENUMERATE,
- NULL,
- },
- JS_FS_END
-};
-
-const JSPropertySpec interface_object_properties[] = {
- JS_PS_END
-};
-
-const JSFunctionSpec interface_object_functions[] = {
- JS_FS_END
-};
-
-const JSPropertySpec own_properties[] = {
- JS_PS_END
-};
-
-void InitializePrototypeAndInterfaceObject(
- InterfaceData* interface_data, JSContext* context,
- JS::HandleObject global_object) {
- DCHECK(!interface_data->prototype);
- DCHECK(!interface_data->interface_object);
- DCHECK(JS_IsGlobalObject(global_object));
-
- JS::RootedObject parent_prototype(
- context, MozjsNamedIndexedGetterInterface::GetPrototype(context, global_object));
- DCHECK(parent_prototype);
-
- // Create the Prototype object.
- interface_data->prototype = JS_NewObjectWithGivenProto(
- context, &interface_data->prototype_class_definition, parent_prototype,
- NULL);
- bool success = JS_DefineProperties(
- context, interface_data->prototype, prototype_properties);
- DCHECK(success);
- success = JS_DefineFunctions(
- context, interface_data->prototype, prototype_functions);
- DCHECK(success);
-
- JS::RootedObject function_prototype(
- context, JS_GetFunctionPrototype(context, global_object));
- DCHECK(function_prototype);
- // Create the Interface object.
- interface_data->interface_object = JS_NewObjectWithGivenProto(
- context, &interface_data->interface_object_class_definition,
- function_prototype, NULL);
-
- // Add the InterfaceObject.name property.
- JS::RootedObject rooted_interface_object(
- context, interface_data->interface_object);
- JS::RootedValue name_value(context);
- const char name[] =
- "DerivedGetterSetterInterface";
- name_value.setString(JS_NewStringCopyZ(context, name));
- success =
- JS_DefineProperty(context, rooted_interface_object, "name", name_value,
- JS_PropertyStub, JS_StrictPropertyStub,
- JSPROP_READONLY);
- DCHECK(success);
-
- // Define interface object properties (including constants).
- success = JS_DefineProperties(context, rooted_interface_object,
- interface_object_properties);
- DCHECK(success);
- // Define interface object functions (static).
- success = JS_DefineFunctions(context, rooted_interface_object,
- interface_object_functions);
- DCHECK(success);
-
-
- // Set the Prototype.constructor and Constructor.prototype properties.
- DCHECK(interface_data->interface_object);
- DCHECK(interface_data->prototype);
- JS::RootedObject rooted_prototype(context, interface_data->prototype);
- success = JS_LinkConstructorAndPrototype(
- context,
- rooted_interface_object,
- rooted_prototype);
- DCHECK(success);
-}
-
-InterfaceData* GetInterfaceData(JSContext* context) {
- MozjsGlobalEnvironment* global_environment =
- static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context));
- // Use the address of the properties definition for this interface as a
- // unique key for looking up the InterfaceData for this interface.
- intptr_t key = reinterpret_cast<intptr_t>(&own_properties);
- InterfaceData* interface_data = global_environment->GetInterfaceData(key);
- if (!interface_data) {
- interface_data = CreateCachedInterfaceData();
- DCHECK(interface_data);
- global_environment->CacheInterfaceData(key, interface_data);
- DCHECK_EQ(interface_data, global_environment->GetInterfaceData(key));
- }
- return interface_data;
-}
-
-} // namespace
-
-// static
-JSObject* MozjsDerivedGetterSetterInterface::CreateProxy(
- JSContext* context, const scoped_refptr<Wrappable>& wrappable) {
- DCHECK(MozjsGlobalEnvironment::GetFromContext(context));
- JS::RootedObject global_object(
- context,
- MozjsGlobalEnvironment::GetFromContext(context)->global_object());
- DCHECK(global_object);
-
- InterfaceData* interface_data = GetInterfaceData(context);
- JS::RootedObject prototype(context, GetPrototype(context, global_object));
- DCHECK(prototype);
- JS::RootedObject new_object(context, JS_NewObjectWithGivenProto(
- context, &interface_data->instance_class_definition, prototype, NULL));
- DCHECK(new_object);
- JS::RootedObject proxy(context,
- ProxyHandler::NewProxy(context, new_object, prototype, NULL,
- proxy_handler.Pointer()));
- WrapperPrivate::AddPrivateData(context, proxy, wrappable);
- return proxy;
-}
-
-//static
-const JSClass* MozjsDerivedGetterSetterInterface::PrototypeClass(
- JSContext* context) {
- DCHECK(MozjsGlobalEnvironment::GetFromContext(context));
- JS::RootedObject global_object(
- context,
- MozjsGlobalEnvironment::GetFromContext(context)->global_object());
- DCHECK(global_object);
-
- JS::RootedObject prototype(context, GetPrototype(context, global_object));
- JSClass* proto_class = JS_GetClass(*prototype.address());
- return proto_class;
-}
-
-// static
-JSObject* MozjsDerivedGetterSetterInterface::GetPrototype(
- JSContext* context, JS::HandleObject global_object) {
- DCHECK(JS_IsGlobalObject(global_object));
-
- InterfaceData* interface_data = GetInterfaceData(context);
- if (!interface_data->prototype) {
- // Create new prototype that has all the props and methods
- InitializePrototypeAndInterfaceObject(
- interface_data, context, global_object);
- }
- DCHECK(interface_data->prototype);
- return interface_data->prototype;
-}
-
-// static
-JSObject* MozjsDerivedGetterSetterInterface::GetInterfaceObject(
- JSContext* context, JS::HandleObject global_object) {
- DCHECK(JS_IsGlobalObject(global_object));
-
- InterfaceData* interface_data = GetInterfaceData(context);
- if (!interface_data->interface_object) {
- InitializePrototypeAndInterfaceObject(
- interface_data, context, global_object);
- }
- DCHECK(interface_data->interface_object);
- return interface_data->interface_object;
-}
-
-
-namespace {
-} // namespace
-
-
-} // namespace testing
-} // namespace bindings
-} // namespace cobalt
diff --git a/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_derived_getter_setter_interface.h b/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_derived_getter_setter_interface.h
deleted file mode 100644
index 8d25c7a..0000000
--- a/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_derived_getter_setter_interface.h
+++ /dev/null
@@ -1,53 +0,0 @@
-// Copyright 2017 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/mozjs/templates/interface.h.template
-
-#ifndef MozjsDerivedGetterSetterInterface_h
-#define MozjsDerivedGetterSetterInterface_h
-
-#include "base/hash_tables.h"
-#include "base/lazy_instance.h"
-#include "base/memory/ref_counted.h"
-#include "base/threading/thread_checker.h"
-#include "cobalt/base/polymorphic_downcast.h"
-#include "cobalt/script/wrappable.h"
-#include "cobalt/bindings/testing/derived_getter_setter_interface.h"
-#include "cobalt/bindings/testing/mozjs_named_indexed_getter_interface.h"
-
-#include "third_party/mozjs/js/src/jsapi.h"
-
-namespace cobalt {
-namespace bindings {
-namespace testing {
-
-class MozjsDerivedGetterSetterInterface {
- public:
- static JSObject* CreateProxy(JSContext* context,
- const scoped_refptr<script::Wrappable>& wrappable);
- static const JSClass* PrototypeClass(JSContext* context);
- static JSObject* GetPrototype(JSContext* context,
- JS::HandleObject global_object);
- static JSObject* GetInterfaceObject(JSContext* context,
- JS::HandleObject global_object);
-};
-
-} // namespace testing
-} // namespace bindings
-} // namespace cobalt
-
-#endif // MozjsDerivedGetterSetterInterface_h
diff --git a/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_derived_interface.cc b/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_derived_interface.cc
deleted file mode 100644
index ca7f7ce..0000000
--- a/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_derived_interface.cc
+++ /dev/null
@@ -1,498 +0,0 @@
-// Copyright 2017 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/mozjs/templates/interface.cc.template
-
-#include "cobalt/bindings/testing/mozjs_derived_interface.h"
-
-#include "base/debug/trace_event.h"
-#include "cobalt/base/polymorphic_downcast.h"
-#include "cobalt/script/global_environment.h"
-#include "cobalt/script/opaque_handle.h"
-#include "cobalt/script/script_value.h"
-#include "cobalt/bindings/testing/base_interface.h"
-#include "cobalt/bindings/testing/mozjs_base_interface.h"
-
-#include "mozjs_gen_type_conversion.h"
-
-#include "base/lazy_instance.h"
-#include "cobalt/script/exception_state.h"
-#include "cobalt/script/mozjs/callback_function_conversion.h"
-#include "cobalt/script/mozjs/conversion_helpers.h"
-#include "cobalt/script/mozjs/mozjs_callback_function.h"
-#include "cobalt/script/mozjs/mozjs_exception_state.h"
-#include "cobalt/script/mozjs/mozjs_global_environment.h"
-#include "cobalt/script/mozjs/mozjs_object_handle.h"
-#include "cobalt/script/mozjs/mozjs_property_enumerator.h"
-#include "cobalt/script/mozjs/mozjs_user_object_holder.h"
-#include "cobalt/script/mozjs/mozjs_value_handle.h"
-#include "cobalt/script/mozjs/native_promise.h"
-#include "cobalt/script/mozjs/proxy_handler.h"
-#include "cobalt/script/mozjs/type_traits.h"
-#include "cobalt/script/mozjs/wrapper_factory.h"
-#include "cobalt/script/mozjs/wrapper_private.h"
-#include "cobalt/script/property_enumerator.h"
-#include "cobalt/script/sequence.h"
-#include "third_party/mozjs/js/src/jsapi.h"
-#include "third_party/mozjs/js/src/jsfriendapi.h"
-
-namespace {
-using cobalt::bindings::testing::DerivedInterface;
-using cobalt::bindings::testing::MozjsDerivedInterface;
-using cobalt::bindings::testing::BaseInterface;
-using cobalt::bindings::testing::MozjsBaseInterface;
-using cobalt::script::CallbackInterfaceTraits;
-using cobalt::script::GlobalEnvironment;
-using cobalt::script::OpaqueHandle;
-using cobalt::script::OpaqueHandleHolder;
-using cobalt::script::ScriptValue;
-using cobalt::script::ValueHandle;
-using cobalt::script::Wrappable;
-
-using cobalt::script::CallbackFunction;
-using cobalt::script::CallbackInterfaceTraits;
-using cobalt::script::ExceptionState;
-using cobalt::script::Wrappable;
-using cobalt::script::mozjs::FromJSValue;
-using cobalt::script::mozjs::InterfaceData;
-using cobalt::script::mozjs::MozjsCallbackFunction;
-using cobalt::script::mozjs::MozjsExceptionState;
-using cobalt::script::mozjs::MozjsGlobalEnvironment;
-using cobalt::script::mozjs::MozjsPropertyEnumerator;
-using cobalt::script::mozjs::MozjsUserObjectHolder;
-using cobalt::script::mozjs::ProxyHandler;
-using cobalt::script::mozjs::ToJSValue;
-using cobalt::script::mozjs::TypeTraits;
-using cobalt::script::mozjs::WrapperFactory;
-using cobalt::script::mozjs::WrapperPrivate;
-using cobalt::script::mozjs::kConversionFlagClamped;
-using cobalt::script::mozjs::kConversionFlagNullable;
-using cobalt::script::mozjs::kConversionFlagRestricted;
-using cobalt::script::mozjs::kConversionFlagTreatNullAsEmptyString;
-using cobalt::script::mozjs::kConversionFlagTreatUndefinedAsEmptyString;
-using cobalt::script::mozjs::kNoConversionFlags;
-} // namespace
-
-namespace cobalt {
-namespace bindings {
-namespace testing {
-
-namespace {
-
-class MozjsDerivedInterfaceHandler : public ProxyHandler {
- public:
- MozjsDerivedInterfaceHandler()
- : ProxyHandler(indexed_property_hooks, named_property_hooks) {}
-
- private:
- static NamedPropertyHooks named_property_hooks;
- static IndexedPropertyHooks indexed_property_hooks;
-};
-
-ProxyHandler::NamedPropertyHooks
-MozjsDerivedInterfaceHandler::named_property_hooks = {
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
-};
-ProxyHandler::IndexedPropertyHooks
-MozjsDerivedInterfaceHandler::indexed_property_hooks = {
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
-};
-
-static base::LazyInstance<MozjsDerivedInterfaceHandler>
- proxy_handler;
-
-JSBool Constructor(JSContext* context, unsigned int argc, JS::Value* vp);
-JSBool HasInstance(JSContext *context, JS::HandleObject type,
- JS::MutableHandleValue vp, JSBool *success) {
- JS::RootedObject global_object(
- context, JS_GetGlobalForObject(context, type));
- DCHECK(global_object);
-
- JS::RootedObject prototype(
- context, MozjsDerivedInterface::GetPrototype(context, global_object));
-
- // |IsDelegate| walks the prototype chain of an object returning true if
- // .prototype is found.
- bool is_delegate;
- if (!IsDelegate(context, prototype, vp, &is_delegate)) {
- *success = false;
- return false;
- }
-
- *success = is_delegate;
- return true;
-}
-
-InterfaceData* CreateCachedInterfaceData() {
- InterfaceData* interface_data = new InterfaceData();
- memset(&interface_data->instance_class_definition, 0,
- sizeof(interface_data->instance_class_definition));
- memset(&interface_data->prototype_class_definition, 0,
- sizeof(interface_data->prototype_class_definition));
- memset(&interface_data->interface_object_class_definition, 0,
- sizeof(interface_data->interface_object_class_definition));
-
- JSClass* instance_class = &interface_data->instance_class_definition;
- const int kGlobalFlags = 0;
- instance_class->name = "DerivedInterface";
- instance_class->flags = kGlobalFlags | JSCLASS_HAS_PRIVATE;
- instance_class->addProperty = JS_PropertyStub;
- instance_class->delProperty = JS_DeletePropertyStub;
- instance_class->getProperty = JS_PropertyStub;
- instance_class->setProperty = JS_StrictPropertyStub;
- instance_class->enumerate = JS_EnumerateStub;
- instance_class->resolve = JS_ResolveStub;
- instance_class->convert = JS_ConvertStub;
- // Function to be called before on object of this class is garbage collected.
- instance_class->finalize = &WrapperPrivate::Finalizer;
- // Called to trace objects that can be referenced from this object.
- instance_class->trace = &WrapperPrivate::Trace;
-
- JSClass* prototype_class = &interface_data->prototype_class_definition;
- prototype_class->name = "DerivedInterfacePrototype";
- prototype_class->flags = 0;
- prototype_class->addProperty = JS_PropertyStub;
- prototype_class->delProperty = JS_DeletePropertyStub;
- prototype_class->getProperty = JS_PropertyStub;
- prototype_class->setProperty = JS_StrictPropertyStub;
- prototype_class->enumerate = JS_EnumerateStub;
- prototype_class->resolve = JS_ResolveStub;
- prototype_class->convert = JS_ConvertStub;
-
- JSClass* interface_object_class =
- &interface_data->interface_object_class_definition;
- interface_object_class->name = "DerivedInterfaceConstructor";
- interface_object_class->flags = 0;
- interface_object_class->addProperty = JS_PropertyStub;
- interface_object_class->delProperty = JS_DeletePropertyStub;
- interface_object_class->getProperty = JS_PropertyStub;
- interface_object_class->setProperty = JS_StrictPropertyStub;
- interface_object_class->enumerate = JS_EnumerateStub;
- interface_object_class->resolve = JS_ResolveStub;
- interface_object_class->convert = JS_ConvertStub;
- interface_object_class->hasInstance = &HasInstance;
- interface_object_class->construct = Constructor;
- return interface_data;
-}
-
-JSBool get_derivedAttribute(
- JSContext* context, JS::HandleObject object, JS::HandleId id,
- JS::MutableHandleValue vp) {
- const JSClass* proto_class =
- MozjsDerivedInterface::PrototypeClass(context);
- if (proto_class == JS_GetClass(object)) {
- // Simply returns true if the object is this class's prototype object.
- // There is no need to return any value due to the object is not a platform
- // object. The execution reaches here when Object.getOwnPropertyDescriptor
- // gets called on native object prototypes.
- return true;
- }
-
- MozjsGlobalEnvironment* global_environment =
- static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context));
- WrapperFactory* wrapper_factory = global_environment->wrapper_factory();
- if (!wrapper_factory->DoesObjectImplementInterface(
- object, base::GetTypeId<DerivedInterface>())) {
- MozjsExceptionState exception(context);
- exception.SetSimpleException(script::kDoesNotImplementInterface);
- return false;
- }
- MozjsExceptionState exception_state(context);
- JS::RootedValue result_value(context);
-
- WrapperPrivate* wrapper_private =
- WrapperPrivate::GetFromObject(context, object);
- DerivedInterface* impl =
- wrapper_private->wrappable<DerivedInterface>().get();
-
- if (!exception_state.is_exception_set()) {
- ToJSValue(context,
- impl->derived_attribute(),
- &result_value);
- }
- if (!exception_state.is_exception_set()) {
- vp.set(result_value);
- }
- return !exception_state.is_exception_set();
-}
-
-JSBool fcn_derivedOperation(
- JSContext* context, uint32_t argc, JS::Value *vp) {
- JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
- // Compute the 'this' value.
- JS::RootedValue this_value(context, JS_ComputeThis(context, vp));
- // 'this' should be an object.
- JS::RootedObject object(context);
- if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) {
- return false;
- }
- if (!JS_ValueToObject(context, this_value, object.address())) {
- NOTREACHED();
- return false;
- }
- const JSClass* proto_class =
- MozjsDerivedInterface::PrototypeClass(context);
- if (proto_class == JS_GetClass(object)) {
- // Simply returns true if the object is this class's prototype object.
- // There is no need to return any value due to the object is not a platform
- // object. The execution reaches here when Object.getOwnPropertyDescriptor
- // gets called on native object prototypes.
- return true;
- }
-
- MozjsGlobalEnvironment* global_environment =
- static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context));
- WrapperFactory* wrapper_factory = global_environment->wrapper_factory();
- if (!wrapper_factory->DoesObjectImplementInterface(
- object, base::GetTypeId<DerivedInterface>())) {
- MozjsExceptionState exception(context);
- exception.SetSimpleException(script::kDoesNotImplementInterface);
- return false;
- }
- MozjsExceptionState exception_state(context);
- JS::RootedValue result_value(context);
-
- WrapperPrivate* wrapper_private =
- WrapperPrivate::GetFromObject(context, object);
- DerivedInterface* impl =
- wrapper_private->wrappable<DerivedInterface>().get();
-
- impl->DerivedOperation();
- result_value.set(JS::UndefinedHandleValue);
- return !exception_state.is_exception_set();
-}
-
-
-const JSPropertySpec prototype_properties[] = {
- { // Readonly attribute
- "derivedAttribute", 0,
- JSPROP_SHARED | JSPROP_ENUMERATE | JSPROP_READONLY,
- JSOP_WRAPPER(&get_derivedAttribute),
- JSOP_NULLWRAPPER,
- },
- JS_PS_END
-};
-
-const JSFunctionSpec prototype_functions[] = {
- {
- "derivedOperation",
- JSOP_WRAPPER(&fcn_derivedOperation),
- 0,
- JSPROP_ENUMERATE,
- NULL,
- },
- JS_FS_END
-};
-
-const JSPropertySpec interface_object_properties[] = {
- JS_PS_END
-};
-
-const JSFunctionSpec interface_object_functions[] = {
- JS_FS_END
-};
-
-const JSPropertySpec own_properties[] = {
- JS_PS_END
-};
-
-void InitializePrototypeAndInterfaceObject(
- InterfaceData* interface_data, JSContext* context,
- JS::HandleObject global_object) {
- DCHECK(!interface_data->prototype);
- DCHECK(!interface_data->interface_object);
- DCHECK(JS_IsGlobalObject(global_object));
-
- JS::RootedObject parent_prototype(
- context, MozjsBaseInterface::GetPrototype(context, global_object));
- DCHECK(parent_prototype);
-
- // Create the Prototype object.
- interface_data->prototype = JS_NewObjectWithGivenProto(
- context, &interface_data->prototype_class_definition, parent_prototype,
- NULL);
- bool success = JS_DefineProperties(
- context, interface_data->prototype, prototype_properties);
- DCHECK(success);
- success = JS_DefineFunctions(
- context, interface_data->prototype, prototype_functions);
- DCHECK(success);
-
- JS::RootedObject function_prototype(
- context, JS_GetFunctionPrototype(context, global_object));
- DCHECK(function_prototype);
- // Create the Interface object.
- interface_data->interface_object = JS_NewObjectWithGivenProto(
- context, &interface_data->interface_object_class_definition,
- function_prototype, NULL);
-
- // Add the InterfaceObject.name property.
- JS::RootedObject rooted_interface_object(
- context, interface_data->interface_object);
- JS::RootedValue name_value(context);
- const char name[] =
- "DerivedInterface";
- name_value.setString(JS_NewStringCopyZ(context, name));
- success =
- JS_DefineProperty(context, rooted_interface_object, "name", name_value,
- JS_PropertyStub, JS_StrictPropertyStub,
- JSPROP_READONLY);
- DCHECK(success);
-
- // Add the InterfaceObject.length property. It is set to the length of the
- // shortest argument list of all overload constructors.
- JS::RootedValue length_value(context);
- length_value.setInt32(0);
- success =
- JS_DefineProperty(context, rooted_interface_object, "length",
- length_value, JS_PropertyStub, JS_StrictPropertyStub,
- JSPROP_READONLY);
- DCHECK(success);
-
- // Define interface object properties (including constants).
- success = JS_DefineProperties(context, rooted_interface_object,
- interface_object_properties);
- DCHECK(success);
- // Define interface object functions (static).
- success = JS_DefineFunctions(context, rooted_interface_object,
- interface_object_functions);
- DCHECK(success);
-
-
- // Set the Prototype.constructor and Constructor.prototype properties.
- DCHECK(interface_data->interface_object);
- DCHECK(interface_data->prototype);
- JS::RootedObject rooted_prototype(context, interface_data->prototype);
- success = JS_LinkConstructorAndPrototype(
- context,
- rooted_interface_object,
- rooted_prototype);
- DCHECK(success);
-}
-
-InterfaceData* GetInterfaceData(JSContext* context) {
- MozjsGlobalEnvironment* global_environment =
- static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context));
- // Use the address of the properties definition for this interface as a
- // unique key for looking up the InterfaceData for this interface.
- intptr_t key = reinterpret_cast<intptr_t>(&own_properties);
- InterfaceData* interface_data = global_environment->GetInterfaceData(key);
- if (!interface_data) {
- interface_data = CreateCachedInterfaceData();
- DCHECK(interface_data);
- global_environment->CacheInterfaceData(key, interface_data);
- DCHECK_EQ(interface_data, global_environment->GetInterfaceData(key));
- }
- return interface_data;
-}
-
-} // namespace
-
-// static
-JSObject* MozjsDerivedInterface::CreateProxy(
- JSContext* context, const scoped_refptr<Wrappable>& wrappable) {
- DCHECK(MozjsGlobalEnvironment::GetFromContext(context));
- JS::RootedObject global_object(
- context,
- MozjsGlobalEnvironment::GetFromContext(context)->global_object());
- DCHECK(global_object);
-
- InterfaceData* interface_data = GetInterfaceData(context);
- JS::RootedObject prototype(context, GetPrototype(context, global_object));
- DCHECK(prototype);
- JS::RootedObject new_object(context, JS_NewObjectWithGivenProto(
- context, &interface_data->instance_class_definition, prototype, NULL));
- DCHECK(new_object);
- JS::RootedObject proxy(context,
- ProxyHandler::NewProxy(context, new_object, prototype, NULL,
- proxy_handler.Pointer()));
- WrapperPrivate::AddPrivateData(context, proxy, wrappable);
- return proxy;
-}
-
-//static
-const JSClass* MozjsDerivedInterface::PrototypeClass(
- JSContext* context) {
- DCHECK(MozjsGlobalEnvironment::GetFromContext(context));
- JS::RootedObject global_object(
- context,
- MozjsGlobalEnvironment::GetFromContext(context)->global_object());
- DCHECK(global_object);
-
- JS::RootedObject prototype(context, GetPrototype(context, global_object));
- JSClass* proto_class = JS_GetClass(*prototype.address());
- return proto_class;
-}
-
-// static
-JSObject* MozjsDerivedInterface::GetPrototype(
- JSContext* context, JS::HandleObject global_object) {
- DCHECK(JS_IsGlobalObject(global_object));
-
- InterfaceData* interface_data = GetInterfaceData(context);
- if (!interface_data->prototype) {
- // Create new prototype that has all the props and methods
- InitializePrototypeAndInterfaceObject(
- interface_data, context, global_object);
- }
- DCHECK(interface_data->prototype);
- return interface_data->prototype;
-}
-
-// static
-JSObject* MozjsDerivedInterface::GetInterfaceObject(
- JSContext* context, JS::HandleObject global_object) {
- DCHECK(JS_IsGlobalObject(global_object));
-
- InterfaceData* interface_data = GetInterfaceData(context);
- if (!interface_data->interface_object) {
- InitializePrototypeAndInterfaceObject(
- interface_data, context, global_object);
- }
- DCHECK(interface_data->interface_object);
- return interface_data->interface_object;
-}
-
-
-namespace {
-JSBool Constructor(JSContext* context, unsigned int argc, JS::Value* vp) {
- MozjsExceptionState exception_state(context);
- JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
-
- scoped_refptr<DerivedInterface> new_object =
- new DerivedInterface();
- JS::RootedValue result_value(context);
- ToJSValue(context, new_object, &result_value);
- DCHECK(result_value.isObject());
- JS::RootedObject result_object(context, JSVAL_TO_OBJECT(result_value));
- args.rval().setObject(*result_object);
- return true;
-}
-} // namespace
-
-
-} // namespace testing
-} // namespace bindings
-} // namespace cobalt
diff --git a/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_derived_interface.h b/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_derived_interface.h
deleted file mode 100644
index 0fd2ca4..0000000
--- a/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_derived_interface.h
+++ /dev/null
@@ -1,53 +0,0 @@
-// Copyright 2017 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/mozjs/templates/interface.h.template
-
-#ifndef MozjsDerivedInterface_h
-#define MozjsDerivedInterface_h
-
-#include "base/hash_tables.h"
-#include "base/lazy_instance.h"
-#include "base/memory/ref_counted.h"
-#include "base/threading/thread_checker.h"
-#include "cobalt/base/polymorphic_downcast.h"
-#include "cobalt/script/wrappable.h"
-#include "cobalt/bindings/testing/derived_interface.h"
-#include "cobalt/bindings/testing/mozjs_base_interface.h"
-
-#include "third_party/mozjs/js/src/jsapi.h"
-
-namespace cobalt {
-namespace bindings {
-namespace testing {
-
-class MozjsDerivedInterface {
- public:
- static JSObject* CreateProxy(JSContext* context,
- const scoped_refptr<script::Wrappable>& wrappable);
- static const JSClass* PrototypeClass(JSContext* context);
- static JSObject* GetPrototype(JSContext* context,
- JS::HandleObject global_object);
- static JSObject* GetInterfaceObject(JSContext* context,
- JS::HandleObject global_object);
-};
-
-} // namespace testing
-} // namespace bindings
-} // namespace cobalt
-
-#endif // MozjsDerivedInterface_h
diff --git a/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_dictionary_interface.cc b/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_dictionary_interface.cc
deleted file mode 100644
index 1a32edc..0000000
--- a/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_dictionary_interface.cc
+++ /dev/null
@@ -1,676 +0,0 @@
-// Copyright 2017 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/mozjs/templates/interface.cc.template
-
-#include "cobalt/bindings/testing/mozjs_dictionary_interface.h"
-
-#include "base/debug/trace_event.h"
-#include "cobalt/base/polymorphic_downcast.h"
-#include "cobalt/script/global_environment.h"
-#include "cobalt/script/opaque_handle.h"
-#include "cobalt/script/script_value.h"
-#include "cobalt/bindings/testing/derived_dictionary.h"
-#include "cobalt/bindings/testing/dictionary_with_dictionary_member.h"
-#include "cobalt/bindings/testing/test_dictionary.h"
-
-#include "mozjs_gen_type_conversion.h"
-
-#include "base/lazy_instance.h"
-#include "cobalt/script/exception_state.h"
-#include "cobalt/script/mozjs/callback_function_conversion.h"
-#include "cobalt/script/mozjs/conversion_helpers.h"
-#include "cobalt/script/mozjs/mozjs_callback_function.h"
-#include "cobalt/script/mozjs/mozjs_exception_state.h"
-#include "cobalt/script/mozjs/mozjs_global_environment.h"
-#include "cobalt/script/mozjs/mozjs_object_handle.h"
-#include "cobalt/script/mozjs/mozjs_property_enumerator.h"
-#include "cobalt/script/mozjs/mozjs_user_object_holder.h"
-#include "cobalt/script/mozjs/mozjs_value_handle.h"
-#include "cobalt/script/mozjs/native_promise.h"
-#include "cobalt/script/mozjs/proxy_handler.h"
-#include "cobalt/script/mozjs/type_traits.h"
-#include "cobalt/script/mozjs/wrapper_factory.h"
-#include "cobalt/script/mozjs/wrapper_private.h"
-#include "cobalt/script/property_enumerator.h"
-#include "cobalt/script/sequence.h"
-#include "third_party/mozjs/js/src/jsapi.h"
-#include "third_party/mozjs/js/src/jsfriendapi.h"
-
-namespace {
-using cobalt::bindings::testing::DictionaryInterface;
-using cobalt::bindings::testing::MozjsDictionaryInterface;
-using cobalt::bindings::testing::DerivedDictionary;
-using cobalt::bindings::testing::DictionaryWithDictionaryMember;
-using cobalt::bindings::testing::TestDictionary;
-using cobalt::script::CallbackInterfaceTraits;
-using cobalt::script::GlobalEnvironment;
-using cobalt::script::OpaqueHandle;
-using cobalt::script::OpaqueHandleHolder;
-using cobalt::script::ScriptValue;
-using cobalt::script::ValueHandle;
-using cobalt::script::Wrappable;
-
-using cobalt::script::CallbackFunction;
-using cobalt::script::CallbackInterfaceTraits;
-using cobalt::script::ExceptionState;
-using cobalt::script::Wrappable;
-using cobalt::script::mozjs::FromJSValue;
-using cobalt::script::mozjs::InterfaceData;
-using cobalt::script::mozjs::MozjsCallbackFunction;
-using cobalt::script::mozjs::MozjsExceptionState;
-using cobalt::script::mozjs::MozjsGlobalEnvironment;
-using cobalt::script::mozjs::MozjsPropertyEnumerator;
-using cobalt::script::mozjs::MozjsUserObjectHolder;
-using cobalt::script::mozjs::ProxyHandler;
-using cobalt::script::mozjs::ToJSValue;
-using cobalt::script::mozjs::TypeTraits;
-using cobalt::script::mozjs::WrapperFactory;
-using cobalt::script::mozjs::WrapperPrivate;
-using cobalt::script::mozjs::kConversionFlagClamped;
-using cobalt::script::mozjs::kConversionFlagNullable;
-using cobalt::script::mozjs::kConversionFlagRestricted;
-using cobalt::script::mozjs::kConversionFlagTreatNullAsEmptyString;
-using cobalt::script::mozjs::kConversionFlagTreatUndefinedAsEmptyString;
-using cobalt::script::mozjs::kNoConversionFlags;
-} // namespace
-
-namespace cobalt {
-namespace bindings {
-namespace testing {
-
-namespace {
-
-class MozjsDictionaryInterfaceHandler : public ProxyHandler {
- public:
- MozjsDictionaryInterfaceHandler()
- : ProxyHandler(indexed_property_hooks, named_property_hooks) {}
-
- private:
- static NamedPropertyHooks named_property_hooks;
- static IndexedPropertyHooks indexed_property_hooks;
-};
-
-ProxyHandler::NamedPropertyHooks
-MozjsDictionaryInterfaceHandler::named_property_hooks = {
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
-};
-ProxyHandler::IndexedPropertyHooks
-MozjsDictionaryInterfaceHandler::indexed_property_hooks = {
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
-};
-
-static base::LazyInstance<MozjsDictionaryInterfaceHandler>
- proxy_handler;
-
-JSBool HasInstance(JSContext *context, JS::HandleObject type,
- JS::MutableHandleValue vp, JSBool *success) {
- JS::RootedObject global_object(
- context, JS_GetGlobalForObject(context, type));
- DCHECK(global_object);
-
- JS::RootedObject prototype(
- context, MozjsDictionaryInterface::GetPrototype(context, global_object));
-
- // |IsDelegate| walks the prototype chain of an object returning true if
- // .prototype is found.
- bool is_delegate;
- if (!IsDelegate(context, prototype, vp, &is_delegate)) {
- *success = false;
- return false;
- }
-
- *success = is_delegate;
- return true;
-}
-
-InterfaceData* CreateCachedInterfaceData() {
- InterfaceData* interface_data = new InterfaceData();
- memset(&interface_data->instance_class_definition, 0,
- sizeof(interface_data->instance_class_definition));
- memset(&interface_data->prototype_class_definition, 0,
- sizeof(interface_data->prototype_class_definition));
- memset(&interface_data->interface_object_class_definition, 0,
- sizeof(interface_data->interface_object_class_definition));
-
- JSClass* instance_class = &interface_data->instance_class_definition;
- const int kGlobalFlags = 0;
- instance_class->name = "DictionaryInterface";
- instance_class->flags = kGlobalFlags | JSCLASS_HAS_PRIVATE;
- instance_class->addProperty = JS_PropertyStub;
- instance_class->delProperty = JS_DeletePropertyStub;
- instance_class->getProperty = JS_PropertyStub;
- instance_class->setProperty = JS_StrictPropertyStub;
- instance_class->enumerate = JS_EnumerateStub;
- instance_class->resolve = JS_ResolveStub;
- instance_class->convert = JS_ConvertStub;
- // Function to be called before on object of this class is garbage collected.
- instance_class->finalize = &WrapperPrivate::Finalizer;
- // Called to trace objects that can be referenced from this object.
- instance_class->trace = &WrapperPrivate::Trace;
-
- JSClass* prototype_class = &interface_data->prototype_class_definition;
- prototype_class->name = "DictionaryInterfacePrototype";
- prototype_class->flags = 0;
- prototype_class->addProperty = JS_PropertyStub;
- prototype_class->delProperty = JS_DeletePropertyStub;
- prototype_class->getProperty = JS_PropertyStub;
- prototype_class->setProperty = JS_StrictPropertyStub;
- prototype_class->enumerate = JS_EnumerateStub;
- prototype_class->resolve = JS_ResolveStub;
- prototype_class->convert = JS_ConvertStub;
-
- JSClass* interface_object_class =
- &interface_data->interface_object_class_definition;
- interface_object_class->name = "DictionaryInterfaceConstructor";
- interface_object_class->flags = 0;
- interface_object_class->addProperty = JS_PropertyStub;
- interface_object_class->delProperty = JS_DeletePropertyStub;
- interface_object_class->getProperty = JS_PropertyStub;
- interface_object_class->setProperty = JS_StrictPropertyStub;
- interface_object_class->enumerate = JS_EnumerateStub;
- interface_object_class->resolve = JS_ResolveStub;
- interface_object_class->convert = JS_ConvertStub;
- interface_object_class->hasInstance = &HasInstance;
- return interface_data;
-}
-
-JSBool get_dictionarySequence(
- JSContext* context, JS::HandleObject object, JS::HandleId id,
- JS::MutableHandleValue vp) {
- const JSClass* proto_class =
- MozjsDictionaryInterface::PrototypeClass(context);
- if (proto_class == JS_GetClass(object)) {
- // Simply returns true if the object is this class's prototype object.
- // There is no need to return any value due to the object is not a platform
- // object. The execution reaches here when Object.getOwnPropertyDescriptor
- // gets called on native object prototypes.
- return true;
- }
-
- MozjsGlobalEnvironment* global_environment =
- static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context));
- WrapperFactory* wrapper_factory = global_environment->wrapper_factory();
- if (!wrapper_factory->DoesObjectImplementInterface(
- object, base::GetTypeId<DictionaryInterface>())) {
- MozjsExceptionState exception(context);
- exception.SetSimpleException(script::kDoesNotImplementInterface);
- return false;
- }
- MozjsExceptionState exception_state(context);
- JS::RootedValue result_value(context);
-
- WrapperPrivate* wrapper_private =
- WrapperPrivate::GetFromObject(context, object);
- DictionaryInterface* impl =
- wrapper_private->wrappable<DictionaryInterface>().get();
-
- if (!exception_state.is_exception_set()) {
- ToJSValue(context,
- impl->dictionary_sequence(),
- &result_value);
- }
- if (!exception_state.is_exception_set()) {
- vp.set(result_value);
- }
- return !exception_state.is_exception_set();
-}
-
-JSBool set_dictionarySequence(
- JSContext* context, JS::HandleObject object, JS::HandleId id,
- JSBool strict, JS::MutableHandleValue vp) {
- const JSClass* proto_class =
- MozjsDictionaryInterface::PrototypeClass(context);
- if (proto_class == JS_GetClass(object)) {
- // Simply returns true if the object is this class's prototype object.
- // There is no need to return any value due to the object is not a platform
- // object. The execution reaches here when Object.getOwnPropertyDescriptor
- // gets called on native object prototypes.
- return true;
- }
-
- MozjsGlobalEnvironment* global_environment =
- static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context));
- WrapperFactory* wrapper_factory = global_environment->wrapper_factory();
- if (!wrapper_factory->DoesObjectImplementInterface(
- object, base::GetTypeId<DictionaryInterface>())) {
- MozjsExceptionState exception(context);
- exception.SetSimpleException(script::kDoesNotImplementInterface);
- return false;
- }
- MozjsExceptionState exception_state(context);
- JS::RootedValue result_value(context);
-
- WrapperPrivate* wrapper_private =
- WrapperPrivate::GetFromObject(context, object);
- DictionaryInterface* impl =
- wrapper_private->wrappable<DictionaryInterface>().get();
- TypeTraits<::cobalt::script::Sequence< TestDictionary > >::ConversionType value;
- FromJSValue(context, vp, kNoConversionFlags, &exception_state,
- &value);
- if (exception_state.is_exception_set()) {
- return false;
- }
-
- impl->set_dictionary_sequence(value);
- result_value.set(JS::UndefinedHandleValue);
- return !exception_state.is_exception_set();
-}
-
-JSBool fcn_derivedDictionaryOperation(
- JSContext* context, uint32_t argc, JS::Value *vp) {
- JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
- // Compute the 'this' value.
- JS::RootedValue this_value(context, JS_ComputeThis(context, vp));
- // 'this' should be an object.
- JS::RootedObject object(context);
- if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) {
- return false;
- }
- if (!JS_ValueToObject(context, this_value, object.address())) {
- NOTREACHED();
- return false;
- }
- const JSClass* proto_class =
- MozjsDictionaryInterface::PrototypeClass(context);
- if (proto_class == JS_GetClass(object)) {
- // Simply returns true if the object is this class's prototype object.
- // There is no need to return any value due to the object is not a platform
- // object. The execution reaches here when Object.getOwnPropertyDescriptor
- // gets called on native object prototypes.
- return true;
- }
-
- MozjsGlobalEnvironment* global_environment =
- static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context));
- WrapperFactory* wrapper_factory = global_environment->wrapper_factory();
- if (!wrapper_factory->DoesObjectImplementInterface(
- object, base::GetTypeId<DictionaryInterface>())) {
- MozjsExceptionState exception(context);
- exception.SetSimpleException(script::kDoesNotImplementInterface);
- return false;
- }
- MozjsExceptionState exception_state(context);
- JS::RootedValue result_value(context);
-
- WrapperPrivate* wrapper_private =
- WrapperPrivate::GetFromObject(context, object);
- DictionaryInterface* impl =
- wrapper_private->wrappable<DictionaryInterface>().get();
- const size_t kMinArguments = 1;
- if (args.length() < kMinArguments) {
- exception_state.SetSimpleException(script::kInvalidNumberOfArguments);
- return false;
- }
- // Non-optional arguments
- TypeTraits<DerivedDictionary >::ConversionType dictionary;
-
- DCHECK_LT(0, args.length());
- JS::RootedValue non_optional_value0(
- context, args[0]);
- FromJSValue(context,
- non_optional_value0,
- kNoConversionFlags,
- &exception_state, &dictionary);
- if (exception_state.is_exception_set()) {
- return false;
- }
-
- impl->DerivedDictionaryOperation(dictionary);
- result_value.set(JS::UndefinedHandleValue);
- return !exception_state.is_exception_set();
-}
-
-JSBool fcn_dictionaryOperation(
- JSContext* context, uint32_t argc, JS::Value *vp) {
- JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
- // Compute the 'this' value.
- JS::RootedValue this_value(context, JS_ComputeThis(context, vp));
- // 'this' should be an object.
- JS::RootedObject object(context);
- if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) {
- return false;
- }
- if (!JS_ValueToObject(context, this_value, object.address())) {
- NOTREACHED();
- return false;
- }
- const JSClass* proto_class =
- MozjsDictionaryInterface::PrototypeClass(context);
- if (proto_class == JS_GetClass(object)) {
- // Simply returns true if the object is this class's prototype object.
- // There is no need to return any value due to the object is not a platform
- // object. The execution reaches here when Object.getOwnPropertyDescriptor
- // gets called on native object prototypes.
- return true;
- }
-
- MozjsGlobalEnvironment* global_environment =
- static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context));
- WrapperFactory* wrapper_factory = global_environment->wrapper_factory();
- if (!wrapper_factory->DoesObjectImplementInterface(
- object, base::GetTypeId<DictionaryInterface>())) {
- MozjsExceptionState exception(context);
- exception.SetSimpleException(script::kDoesNotImplementInterface);
- return false;
- }
- MozjsExceptionState exception_state(context);
- JS::RootedValue result_value(context);
-
- WrapperPrivate* wrapper_private =
- WrapperPrivate::GetFromObject(context, object);
- DictionaryInterface* impl =
- wrapper_private->wrappable<DictionaryInterface>().get();
- const size_t kMinArguments = 1;
- if (args.length() < kMinArguments) {
- exception_state.SetSimpleException(script::kInvalidNumberOfArguments);
- return false;
- }
- // Non-optional arguments
- TypeTraits<TestDictionary >::ConversionType dictionary;
-
- DCHECK_LT(0, args.length());
- JS::RootedValue non_optional_value0(
- context, args[0]);
- FromJSValue(context,
- non_optional_value0,
- kNoConversionFlags,
- &exception_state, &dictionary);
- if (exception_state.is_exception_set()) {
- return false;
- }
-
- impl->DictionaryOperation(dictionary);
- result_value.set(JS::UndefinedHandleValue);
- return !exception_state.is_exception_set();
-}
-
-JSBool fcn_testOperation(
- JSContext* context, uint32_t argc, JS::Value *vp) {
- JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
- // Compute the 'this' value.
- JS::RootedValue this_value(context, JS_ComputeThis(context, vp));
- // 'this' should be an object.
- JS::RootedObject object(context);
- if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) {
- return false;
- }
- if (!JS_ValueToObject(context, this_value, object.address())) {
- NOTREACHED();
- return false;
- }
- const JSClass* proto_class =
- MozjsDictionaryInterface::PrototypeClass(context);
- if (proto_class == JS_GetClass(object)) {
- // Simply returns true if the object is this class's prototype object.
- // There is no need to return any value due to the object is not a platform
- // object. The execution reaches here when Object.getOwnPropertyDescriptor
- // gets called on native object prototypes.
- return true;
- }
-
- MozjsGlobalEnvironment* global_environment =
- static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context));
- WrapperFactory* wrapper_factory = global_environment->wrapper_factory();
- if (!wrapper_factory->DoesObjectImplementInterface(
- object, base::GetTypeId<DictionaryInterface>())) {
- MozjsExceptionState exception(context);
- exception.SetSimpleException(script::kDoesNotImplementInterface);
- return false;
- }
- MozjsExceptionState exception_state(context);
- JS::RootedValue result_value(context);
-
- WrapperPrivate* wrapper_private =
- WrapperPrivate::GetFromObject(context, object);
- DictionaryInterface* impl =
- wrapper_private->wrappable<DictionaryInterface>().get();
- const size_t kMinArguments = 1;
- if (args.length() < kMinArguments) {
- exception_state.SetSimpleException(script::kInvalidNumberOfArguments);
- return false;
- }
- // Non-optional arguments
- TypeTraits<DictionaryWithDictionaryMember >::ConversionType dict;
-
- DCHECK_LT(0, args.length());
- JS::RootedValue non_optional_value0(
- context, args[0]);
- FromJSValue(context,
- non_optional_value0,
- kNoConversionFlags,
- &exception_state, &dict);
- if (exception_state.is_exception_set()) {
- return false;
- }
-
- impl->TestOperation(dict);
- result_value.set(JS::UndefinedHandleValue);
- return !exception_state.is_exception_set();
-}
-
-
-const JSPropertySpec prototype_properties[] = {
- { // Read/Write property
- "dictionarySequence", 0,
- JSPROP_SHARED | JSPROP_ENUMERATE,
- JSOP_WRAPPER(&get_dictionarySequence),
- JSOP_WRAPPER(&set_dictionarySequence),
- },
- JS_PS_END
-};
-
-const JSFunctionSpec prototype_functions[] = {
- {
- "derivedDictionaryOperation",
- JSOP_WRAPPER(&fcn_derivedDictionaryOperation),
- 1,
- JSPROP_ENUMERATE,
- NULL,
- },
- {
- "dictionaryOperation",
- JSOP_WRAPPER(&fcn_dictionaryOperation),
- 1,
- JSPROP_ENUMERATE,
- NULL,
- },
- {
- "testOperation",
- JSOP_WRAPPER(&fcn_testOperation),
- 1,
- JSPROP_ENUMERATE,
- NULL,
- },
- JS_FS_END
-};
-
-const JSPropertySpec interface_object_properties[] = {
- JS_PS_END
-};
-
-const JSFunctionSpec interface_object_functions[] = {
- JS_FS_END
-};
-
-const JSPropertySpec own_properties[] = {
- JS_PS_END
-};
-
-void InitializePrototypeAndInterfaceObject(
- InterfaceData* interface_data, JSContext* context,
- JS::HandleObject global_object) {
- DCHECK(!interface_data->prototype);
- DCHECK(!interface_data->interface_object);
- DCHECK(JS_IsGlobalObject(global_object));
-
- JS::RootedObject parent_prototype(
- context, JS_GetObjectPrototype(context, global_object));
- DCHECK(parent_prototype);
-
- // Create the Prototype object.
- interface_data->prototype = JS_NewObjectWithGivenProto(
- context, &interface_data->prototype_class_definition, parent_prototype,
- NULL);
- bool success = JS_DefineProperties(
- context, interface_data->prototype, prototype_properties);
- DCHECK(success);
- success = JS_DefineFunctions(
- context, interface_data->prototype, prototype_functions);
- DCHECK(success);
-
- JS::RootedObject function_prototype(
- context, JS_GetFunctionPrototype(context, global_object));
- DCHECK(function_prototype);
- // Create the Interface object.
- interface_data->interface_object = JS_NewObjectWithGivenProto(
- context, &interface_data->interface_object_class_definition,
- function_prototype, NULL);
-
- // Add the InterfaceObject.name property.
- JS::RootedObject rooted_interface_object(
- context, interface_data->interface_object);
- JS::RootedValue name_value(context);
- const char name[] =
- "DictionaryInterface";
- name_value.setString(JS_NewStringCopyZ(context, name));
- success =
- JS_DefineProperty(context, rooted_interface_object, "name", name_value,
- JS_PropertyStub, JS_StrictPropertyStub,
- JSPROP_READONLY);
- DCHECK(success);
-
- // Define interface object properties (including constants).
- success = JS_DefineProperties(context, rooted_interface_object,
- interface_object_properties);
- DCHECK(success);
- // Define interface object functions (static).
- success = JS_DefineFunctions(context, rooted_interface_object,
- interface_object_functions);
- DCHECK(success);
-
-
- // Set the Prototype.constructor and Constructor.prototype properties.
- DCHECK(interface_data->interface_object);
- DCHECK(interface_data->prototype);
- JS::RootedObject rooted_prototype(context, interface_data->prototype);
- success = JS_LinkConstructorAndPrototype(
- context,
- rooted_interface_object,
- rooted_prototype);
- DCHECK(success);
-}
-
-InterfaceData* GetInterfaceData(JSContext* context) {
- MozjsGlobalEnvironment* global_environment =
- static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context));
- // Use the address of the properties definition for this interface as a
- // unique key for looking up the InterfaceData for this interface.
- intptr_t key = reinterpret_cast<intptr_t>(&own_properties);
- InterfaceData* interface_data = global_environment->GetInterfaceData(key);
- if (!interface_data) {
- interface_data = CreateCachedInterfaceData();
- DCHECK(interface_data);
- global_environment->CacheInterfaceData(key, interface_data);
- DCHECK_EQ(interface_data, global_environment->GetInterfaceData(key));
- }
- return interface_data;
-}
-
-} // namespace
-
-// static
-JSObject* MozjsDictionaryInterface::CreateProxy(
- JSContext* context, const scoped_refptr<Wrappable>& wrappable) {
- DCHECK(MozjsGlobalEnvironment::GetFromContext(context));
- JS::RootedObject global_object(
- context,
- MozjsGlobalEnvironment::GetFromContext(context)->global_object());
- DCHECK(global_object);
-
- InterfaceData* interface_data = GetInterfaceData(context);
- JS::RootedObject prototype(context, GetPrototype(context, global_object));
- DCHECK(prototype);
- JS::RootedObject new_object(context, JS_NewObjectWithGivenProto(
- context, &interface_data->instance_class_definition, prototype, NULL));
- DCHECK(new_object);
- JS::RootedObject proxy(context,
- ProxyHandler::NewProxy(context, new_object, prototype, NULL,
- proxy_handler.Pointer()));
- WrapperPrivate::AddPrivateData(context, proxy, wrappable);
- return proxy;
-}
-
-//static
-const JSClass* MozjsDictionaryInterface::PrototypeClass(
- JSContext* context) {
- DCHECK(MozjsGlobalEnvironment::GetFromContext(context));
- JS::RootedObject global_object(
- context,
- MozjsGlobalEnvironment::GetFromContext(context)->global_object());
- DCHECK(global_object);
-
- JS::RootedObject prototype(context, GetPrototype(context, global_object));
- JSClass* proto_class = JS_GetClass(*prototype.address());
- return proto_class;
-}
-
-// static
-JSObject* MozjsDictionaryInterface::GetPrototype(
- JSContext* context, JS::HandleObject global_object) {
- DCHECK(JS_IsGlobalObject(global_object));
-
- InterfaceData* interface_data = GetInterfaceData(context);
- if (!interface_data->prototype) {
- // Create new prototype that has all the props and methods
- InitializePrototypeAndInterfaceObject(
- interface_data, context, global_object);
- }
- DCHECK(interface_data->prototype);
- return interface_data->prototype;
-}
-
-// static
-JSObject* MozjsDictionaryInterface::GetInterfaceObject(
- JSContext* context, JS::HandleObject global_object) {
- DCHECK(JS_IsGlobalObject(global_object));
-
- InterfaceData* interface_data = GetInterfaceData(context);
- if (!interface_data->interface_object) {
- InitializePrototypeAndInterfaceObject(
- interface_data, context, global_object);
- }
- DCHECK(interface_data->interface_object);
- return interface_data->interface_object;
-}
-
-
-namespace {
-} // namespace
-
-
-} // namespace testing
-} // namespace bindings
-} // namespace cobalt
diff --git a/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_dictionary_interface.h b/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_dictionary_interface.h
deleted file mode 100644
index 3fdd54b..0000000
--- a/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_dictionary_interface.h
+++ /dev/null
@@ -1,52 +0,0 @@
-// Copyright 2017 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/mozjs/templates/interface.h.template
-
-#ifndef MozjsDictionaryInterface_h
-#define MozjsDictionaryInterface_h
-
-#include "base/hash_tables.h"
-#include "base/lazy_instance.h"
-#include "base/memory/ref_counted.h"
-#include "base/threading/thread_checker.h"
-#include "cobalt/base/polymorphic_downcast.h"
-#include "cobalt/script/wrappable.h"
-#include "cobalt/bindings/testing/dictionary_interface.h"
-
-#include "third_party/mozjs/js/src/jsapi.h"
-
-namespace cobalt {
-namespace bindings {
-namespace testing {
-
-class MozjsDictionaryInterface {
- public:
- static JSObject* CreateProxy(JSContext* context,
- const scoped_refptr<script::Wrappable>& wrappable);
- static const JSClass* PrototypeClass(JSContext* context);
- static JSObject* GetPrototype(JSContext* context,
- JS::HandleObject global_object);
- static JSObject* GetInterfaceObject(JSContext* context,
- JS::HandleObject global_object);
-};
-
-} // namespace testing
-} // namespace bindings
-} // namespace cobalt
-
-#endif // MozjsDictionaryInterface_h
diff --git a/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_dictionary_with_dictionary_member.cc b/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_dictionary_with_dictionary_member.cc
deleted file mode 100644
index 50e5fde..0000000
--- a/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_dictionary_with_dictionary_member.cc
+++ /dev/null
@@ -1,101 +0,0 @@
-/*
- * Copyright 2017 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/mozjs/templates/dictionary-conversion.cc.template
-
-#include "mozjs_gen_type_conversion.h"
-
-#include "cobalt/bindings/testing/dictionary_with_dictionary_member.h"
-
-#include "cobalt/script/exception_state.h"
-#include "third_party/mozjs/js/src/jsapi.h"
-#include "cobalt/bindings/testing/test_dictionary.h"
-
-using cobalt::bindings::testing::DictionaryWithDictionaryMember;
-using cobalt::bindings::testing::TestDictionary;
-
-namespace cobalt {
-namespace script {
-namespace mozjs {
-
-void ToJSValue(
- JSContext* context,
- const DictionaryWithDictionaryMember& in_dictionary,
- JS::MutableHandleValue out_value) {
- // Create a new object that will hold the dictionary values.
- JS::RootedObject dictionary_object(
- context, JS_NewObject(context, NULL, NULL, NULL));
- const int kPropertyAttributes = JSPROP_ENUMERATE;
- if (in_dictionary.has_nested_dictionary()) {
- JS::RootedValue member_value(context);
- ToJSValue(context, in_dictionary.nested_dictionary(), &member_value);
- if (!JS_DefineProperty(context, dictionary_object,
- "nestedDictionary",
- member_value, NULL, NULL, kPropertyAttributes)) {
- // Some internal error occurred.
- NOTREACHED();
- return;
- }
- }
- out_value.set(OBJECT_TO_JSVAL(dictionary_object));
-}
-
-void FromJSValue(JSContext* context, JS::HandleValue value,
- int conversion_flags, ExceptionState* exception_state,
- DictionaryWithDictionaryMember* out_dictionary) {
- DCHECK_EQ(0, conversion_flags) << "Unexpected conversion flags.";
- // https://heycam.github.io/webidl/#es-dictionary
-
- if (value.isUndefined() || value.isNull()) {
- // The default constructor will assign appropriate values to dictionary
- // members with default values and leave the others unset.
- *out_dictionary = DictionaryWithDictionaryMember();
- return;
- }
- if (!value.isObject()) {
- // 1. If Type(V) is not Undefined, Null or Object, then throw a TypeError.
- exception_state->SetSimpleException(kNotObjectType);
- return;
- }
- JS::RootedObject dictionary_object(context, JSVAL_TO_OBJECT(value));
- JS::RootedValue nested_dictionary(context);
- if (!JS_GetProperty(context, dictionary_object,
- "nestedDictionary",
- nested_dictionary.address())) {
- exception_state->SetSimpleException(kSimpleError);
- return;
- }
- if (!nested_dictionary.isUndefined()) {
- TestDictionary converted_value;
- FromJSValue(context,
- nested_dictionary,
- kNoConversionFlags,
- exception_state,
- &converted_value);
- if (context->isExceptionPending()) {
- return;
- }
- out_dictionary->set_nested_dictionary(converted_value);
- }
-}
-
-} // namespace mozjs
-} // namespace script
-} // namespace cobalt
-
diff --git a/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_disabled_interface.cc b/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_disabled_interface.cc
deleted file mode 100644
index c3cbbef..0000000
--- a/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_disabled_interface.cc
+++ /dev/null
@@ -1,513 +0,0 @@
-// Copyright 2017 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/mozjs/templates/interface.cc.template
-
-#if defined(NO_ENABLE_CONDITIONAL_INTERFACE)
-
-#include "cobalt/bindings/testing/mozjs_disabled_interface.h"
-
-#include "base/debug/trace_event.h"
-#include "cobalt/base/polymorphic_downcast.h"
-#include "cobalt/script/global_environment.h"
-#include "cobalt/script/opaque_handle.h"
-#include "cobalt/script/script_value.h"
-
-#include "mozjs_gen_type_conversion.h"
-
-#include "base/lazy_instance.h"
-#include "cobalt/script/exception_state.h"
-#include "cobalt/script/mozjs/callback_function_conversion.h"
-#include "cobalt/script/mozjs/conversion_helpers.h"
-#include "cobalt/script/mozjs/mozjs_callback_function.h"
-#include "cobalt/script/mozjs/mozjs_exception_state.h"
-#include "cobalt/script/mozjs/mozjs_global_environment.h"
-#include "cobalt/script/mozjs/mozjs_object_handle.h"
-#include "cobalt/script/mozjs/mozjs_property_enumerator.h"
-#include "cobalt/script/mozjs/mozjs_user_object_holder.h"
-#include "cobalt/script/mozjs/mozjs_value_handle.h"
-#include "cobalt/script/mozjs/native_promise.h"
-#include "cobalt/script/mozjs/proxy_handler.h"
-#include "cobalt/script/mozjs/type_traits.h"
-#include "cobalt/script/mozjs/wrapper_factory.h"
-#include "cobalt/script/mozjs/wrapper_private.h"
-#include "cobalt/script/property_enumerator.h"
-#include "cobalt/script/sequence.h"
-#include "third_party/mozjs/js/src/jsapi.h"
-#include "third_party/mozjs/js/src/jsfriendapi.h"
-
-namespace {
-using cobalt::bindings::testing::DisabledInterface;
-using cobalt::bindings::testing::MozjsDisabledInterface;
-using cobalt::script::CallbackInterfaceTraits;
-using cobalt::script::GlobalEnvironment;
-using cobalt::script::OpaqueHandle;
-using cobalt::script::OpaqueHandleHolder;
-using cobalt::script::ScriptValue;
-using cobalt::script::ValueHandle;
-using cobalt::script::Wrappable;
-
-using cobalt::script::CallbackFunction;
-using cobalt::script::CallbackInterfaceTraits;
-using cobalt::script::ExceptionState;
-using cobalt::script::Wrappable;
-using cobalt::script::mozjs::FromJSValue;
-using cobalt::script::mozjs::InterfaceData;
-using cobalt::script::mozjs::MozjsCallbackFunction;
-using cobalt::script::mozjs::MozjsExceptionState;
-using cobalt::script::mozjs::MozjsGlobalEnvironment;
-using cobalt::script::mozjs::MozjsPropertyEnumerator;
-using cobalt::script::mozjs::MozjsUserObjectHolder;
-using cobalt::script::mozjs::ProxyHandler;
-using cobalt::script::mozjs::ToJSValue;
-using cobalt::script::mozjs::TypeTraits;
-using cobalt::script::mozjs::WrapperFactory;
-using cobalt::script::mozjs::WrapperPrivate;
-using cobalt::script::mozjs::kConversionFlagClamped;
-using cobalt::script::mozjs::kConversionFlagNullable;
-using cobalt::script::mozjs::kConversionFlagRestricted;
-using cobalt::script::mozjs::kConversionFlagTreatNullAsEmptyString;
-using cobalt::script::mozjs::kConversionFlagTreatUndefinedAsEmptyString;
-using cobalt::script::mozjs::kNoConversionFlags;
-} // namespace
-
-namespace cobalt {
-namespace bindings {
-namespace testing {
-
-namespace {
-
-class MozjsDisabledInterfaceHandler : public ProxyHandler {
- public:
- MozjsDisabledInterfaceHandler()
- : ProxyHandler(indexed_property_hooks, named_property_hooks) {}
-
- private:
- static NamedPropertyHooks named_property_hooks;
- static IndexedPropertyHooks indexed_property_hooks;
-};
-
-ProxyHandler::NamedPropertyHooks
-MozjsDisabledInterfaceHandler::named_property_hooks = {
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
-};
-ProxyHandler::IndexedPropertyHooks
-MozjsDisabledInterfaceHandler::indexed_property_hooks = {
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
-};
-
-static base::LazyInstance<MozjsDisabledInterfaceHandler>
- proxy_handler;
-
-JSBool HasInstance(JSContext *context, JS::HandleObject type,
- JS::MutableHandleValue vp, JSBool *success) {
- JS::RootedObject global_object(
- context, JS_GetGlobalForObject(context, type));
- DCHECK(global_object);
-
- JS::RootedObject prototype(
- context, MozjsDisabledInterface::GetPrototype(context, global_object));
-
- // |IsDelegate| walks the prototype chain of an object returning true if
- // .prototype is found.
- bool is_delegate;
- if (!IsDelegate(context, prototype, vp, &is_delegate)) {
- *success = false;
- return false;
- }
-
- *success = is_delegate;
- return true;
-}
-
-InterfaceData* CreateCachedInterfaceData() {
- InterfaceData* interface_data = new InterfaceData();
- memset(&interface_data->instance_class_definition, 0,
- sizeof(interface_data->instance_class_definition));
- memset(&interface_data->prototype_class_definition, 0,
- sizeof(interface_data->prototype_class_definition));
- memset(&interface_data->interface_object_class_definition, 0,
- sizeof(interface_data->interface_object_class_definition));
-
- JSClass* instance_class = &interface_data->instance_class_definition;
- const int kGlobalFlags = 0;
- instance_class->name = "DisabledInterface";
- instance_class->flags = kGlobalFlags | JSCLASS_HAS_PRIVATE;
- instance_class->addProperty = JS_PropertyStub;
- instance_class->delProperty = JS_DeletePropertyStub;
- instance_class->getProperty = JS_PropertyStub;
- instance_class->setProperty = JS_StrictPropertyStub;
- instance_class->enumerate = JS_EnumerateStub;
- instance_class->resolve = JS_ResolveStub;
- instance_class->convert = JS_ConvertStub;
- // Function to be called before on object of this class is garbage collected.
- instance_class->finalize = &WrapperPrivate::Finalizer;
- // Called to trace objects that can be referenced from this object.
- instance_class->trace = &WrapperPrivate::Trace;
-
- JSClass* prototype_class = &interface_data->prototype_class_definition;
- prototype_class->name = "DisabledInterfacePrototype";
- prototype_class->flags = 0;
- prototype_class->addProperty = JS_PropertyStub;
- prototype_class->delProperty = JS_DeletePropertyStub;
- prototype_class->getProperty = JS_PropertyStub;
- prototype_class->setProperty = JS_StrictPropertyStub;
- prototype_class->enumerate = JS_EnumerateStub;
- prototype_class->resolve = JS_ResolveStub;
- prototype_class->convert = JS_ConvertStub;
-
- JSClass* interface_object_class =
- &interface_data->interface_object_class_definition;
- interface_object_class->name = "DisabledInterfaceConstructor";
- interface_object_class->flags = 0;
- interface_object_class->addProperty = JS_PropertyStub;
- interface_object_class->delProperty = JS_DeletePropertyStub;
- interface_object_class->getProperty = JS_PropertyStub;
- interface_object_class->setProperty = JS_StrictPropertyStub;
- interface_object_class->enumerate = JS_EnumerateStub;
- interface_object_class->resolve = JS_ResolveStub;
- interface_object_class->convert = JS_ConvertStub;
- interface_object_class->hasInstance = &HasInstance;
- return interface_data;
-}
-
-JSBool get_disabledProperty(
- JSContext* context, JS::HandleObject object, JS::HandleId id,
- JS::MutableHandleValue vp) {
- const JSClass* proto_class =
- MozjsDisabledInterface::PrototypeClass(context);
- if (proto_class == JS_GetClass(object)) {
- // Simply returns true if the object is this class's prototype object.
- // There is no need to return any value due to the object is not a platform
- // object. The execution reaches here when Object.getOwnPropertyDescriptor
- // gets called on native object prototypes.
- return true;
- }
-
- MozjsGlobalEnvironment* global_environment =
- static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context));
- WrapperFactory* wrapper_factory = global_environment->wrapper_factory();
- if (!wrapper_factory->DoesObjectImplementInterface(
- object, base::GetTypeId<DisabledInterface>())) {
- MozjsExceptionState exception(context);
- exception.SetSimpleException(script::kDoesNotImplementInterface);
- return false;
- }
- MozjsExceptionState exception_state(context);
- JS::RootedValue result_value(context);
-
- WrapperPrivate* wrapper_private =
- WrapperPrivate::GetFromObject(context, object);
- DisabledInterface* impl =
- wrapper_private->wrappable<DisabledInterface>().get();
-
- if (!exception_state.is_exception_set()) {
- ToJSValue(context,
- impl->disabled_property(),
- &result_value);
- }
- if (!exception_state.is_exception_set()) {
- vp.set(result_value);
- }
- return !exception_state.is_exception_set();
-}
-
-JSBool set_disabledProperty(
- JSContext* context, JS::HandleObject object, JS::HandleId id,
- JSBool strict, JS::MutableHandleValue vp) {
- const JSClass* proto_class =
- MozjsDisabledInterface::PrototypeClass(context);
- if (proto_class == JS_GetClass(object)) {
- // Simply returns true if the object is this class's prototype object.
- // There is no need to return any value due to the object is not a platform
- // object. The execution reaches here when Object.getOwnPropertyDescriptor
- // gets called on native object prototypes.
- return true;
- }
-
- MozjsGlobalEnvironment* global_environment =
- static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context));
- WrapperFactory* wrapper_factory = global_environment->wrapper_factory();
- if (!wrapper_factory->DoesObjectImplementInterface(
- object, base::GetTypeId<DisabledInterface>())) {
- MozjsExceptionState exception(context);
- exception.SetSimpleException(script::kDoesNotImplementInterface);
- return false;
- }
- MozjsExceptionState exception_state(context);
- JS::RootedValue result_value(context);
-
- WrapperPrivate* wrapper_private =
- WrapperPrivate::GetFromObject(context, object);
- DisabledInterface* impl =
- wrapper_private->wrappable<DisabledInterface>().get();
- TypeTraits<int32_t >::ConversionType value;
- FromJSValue(context, vp, kNoConversionFlags, &exception_state,
- &value);
- if (exception_state.is_exception_set()) {
- return false;
- }
-
- impl->set_disabled_property(value);
- result_value.set(JS::UndefinedHandleValue);
- return !exception_state.is_exception_set();
-}
-
-JSBool fcn_disabledFunction(
- JSContext* context, uint32_t argc, JS::Value *vp) {
- JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
- // Compute the 'this' value.
- JS::RootedValue this_value(context, JS_ComputeThis(context, vp));
- // 'this' should be an object.
- JS::RootedObject object(context);
- if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) {
- return false;
- }
- if (!JS_ValueToObject(context, this_value, object.address())) {
- NOTREACHED();
- return false;
- }
- const JSClass* proto_class =
- MozjsDisabledInterface::PrototypeClass(context);
- if (proto_class == JS_GetClass(object)) {
- // Simply returns true if the object is this class's prototype object.
- // There is no need to return any value due to the object is not a platform
- // object. The execution reaches here when Object.getOwnPropertyDescriptor
- // gets called on native object prototypes.
- return true;
- }
-
- MozjsGlobalEnvironment* global_environment =
- static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context));
- WrapperFactory* wrapper_factory = global_environment->wrapper_factory();
- if (!wrapper_factory->DoesObjectImplementInterface(
- object, base::GetTypeId<DisabledInterface>())) {
- MozjsExceptionState exception(context);
- exception.SetSimpleException(script::kDoesNotImplementInterface);
- return false;
- }
- MozjsExceptionState exception_state(context);
- JS::RootedValue result_value(context);
-
- WrapperPrivate* wrapper_private =
- WrapperPrivate::GetFromObject(context, object);
- DisabledInterface* impl =
- wrapper_private->wrappable<DisabledInterface>().get();
-
- impl->DisabledFunction();
- result_value.set(JS::UndefinedHandleValue);
- return !exception_state.is_exception_set();
-}
-
-
-const JSPropertySpec prototype_properties[] = {
- { // Read/Write property
- "disabledProperty", 0,
- JSPROP_SHARED | JSPROP_ENUMERATE,
- JSOP_WRAPPER(&get_disabledProperty),
- JSOP_WRAPPER(&set_disabledProperty),
- },
- JS_PS_END
-};
-
-const JSFunctionSpec prototype_functions[] = {
- {
- "disabledFunction",
- JSOP_WRAPPER(&fcn_disabledFunction),
- 0,
- JSPROP_ENUMERATE,
- NULL,
- },
- JS_FS_END
-};
-
-const JSPropertySpec interface_object_properties[] = {
- JS_PS_END
-};
-
-const JSFunctionSpec interface_object_functions[] = {
- JS_FS_END
-};
-
-const JSPropertySpec own_properties[] = {
- JS_PS_END
-};
-
-void InitializePrototypeAndInterfaceObject(
- InterfaceData* interface_data, JSContext* context,
- JS::HandleObject global_object) {
- DCHECK(!interface_data->prototype);
- DCHECK(!interface_data->interface_object);
- DCHECK(JS_IsGlobalObject(global_object));
-
- JS::RootedObject parent_prototype(
- context, JS_GetObjectPrototype(context, global_object));
- DCHECK(parent_prototype);
-
- // Create the Prototype object.
- interface_data->prototype = JS_NewObjectWithGivenProto(
- context, &interface_data->prototype_class_definition, parent_prototype,
- NULL);
- bool success = JS_DefineProperties(
- context, interface_data->prototype, prototype_properties);
- DCHECK(success);
- success = JS_DefineFunctions(
- context, interface_data->prototype, prototype_functions);
- DCHECK(success);
-
- JS::RootedObject function_prototype(
- context, JS_GetFunctionPrototype(context, global_object));
- DCHECK(function_prototype);
- // Create the Interface object.
- interface_data->interface_object = JS_NewObjectWithGivenProto(
- context, &interface_data->interface_object_class_definition,
- function_prototype, NULL);
-
- // Add the InterfaceObject.name property.
- JS::RootedObject rooted_interface_object(
- context, interface_data->interface_object);
- JS::RootedValue name_value(context);
- const char name[] =
- "DisabledInterface";
- name_value.setString(JS_NewStringCopyZ(context, name));
- success =
- JS_DefineProperty(context, rooted_interface_object, "name", name_value,
- JS_PropertyStub, JS_StrictPropertyStub,
- JSPROP_READONLY);
- DCHECK(success);
-
- // Define interface object properties (including constants).
- success = JS_DefineProperties(context, rooted_interface_object,
- interface_object_properties);
- DCHECK(success);
- // Define interface object functions (static).
- success = JS_DefineFunctions(context, rooted_interface_object,
- interface_object_functions);
- DCHECK(success);
-
-
- // Set the Prototype.constructor and Constructor.prototype properties.
- DCHECK(interface_data->interface_object);
- DCHECK(interface_data->prototype);
- JS::RootedObject rooted_prototype(context, interface_data->prototype);
- success = JS_LinkConstructorAndPrototype(
- context,
- rooted_interface_object,
- rooted_prototype);
- DCHECK(success);
-}
-
-InterfaceData* GetInterfaceData(JSContext* context) {
- MozjsGlobalEnvironment* global_environment =
- static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context));
- // Use the address of the properties definition for this interface as a
- // unique key for looking up the InterfaceData for this interface.
- intptr_t key = reinterpret_cast<intptr_t>(&own_properties);
- InterfaceData* interface_data = global_environment->GetInterfaceData(key);
- if (!interface_data) {
- interface_data = CreateCachedInterfaceData();
- DCHECK(interface_data);
- global_environment->CacheInterfaceData(key, interface_data);
- DCHECK_EQ(interface_data, global_environment->GetInterfaceData(key));
- }
- return interface_data;
-}
-
-} // namespace
-
-// static
-JSObject* MozjsDisabledInterface::CreateProxy(
- JSContext* context, const scoped_refptr<Wrappable>& wrappable) {
- DCHECK(MozjsGlobalEnvironment::GetFromContext(context));
- JS::RootedObject global_object(
- context,
- MozjsGlobalEnvironment::GetFromContext(context)->global_object());
- DCHECK(global_object);
-
- InterfaceData* interface_data = GetInterfaceData(context);
- JS::RootedObject prototype(context, GetPrototype(context, global_object));
- DCHECK(prototype);
- JS::RootedObject new_object(context, JS_NewObjectWithGivenProto(
- context, &interface_data->instance_class_definition, prototype, NULL));
- DCHECK(new_object);
- JS::RootedObject proxy(context,
- ProxyHandler::NewProxy(context, new_object, prototype, NULL,
- proxy_handler.Pointer()));
- WrapperPrivate::AddPrivateData(context, proxy, wrappable);
- return proxy;
-}
-
-//static
-const JSClass* MozjsDisabledInterface::PrototypeClass(
- JSContext* context) {
- DCHECK(MozjsGlobalEnvironment::GetFromContext(context));
- JS::RootedObject global_object(
- context,
- MozjsGlobalEnvironment::GetFromContext(context)->global_object());
- DCHECK(global_object);
-
- JS::RootedObject prototype(context, GetPrototype(context, global_object));
- JSClass* proto_class = JS_GetClass(*prototype.address());
- return proto_class;
-}
-
-// static
-JSObject* MozjsDisabledInterface::GetPrototype(
- JSContext* context, JS::HandleObject global_object) {
- DCHECK(JS_IsGlobalObject(global_object));
-
- InterfaceData* interface_data = GetInterfaceData(context);
- if (!interface_data->prototype) {
- // Create new prototype that has all the props and methods
- InitializePrototypeAndInterfaceObject(
- interface_data, context, global_object);
- }
- DCHECK(interface_data->prototype);
- return interface_data->prototype;
-}
-
-// static
-JSObject* MozjsDisabledInterface::GetInterfaceObject(
- JSContext* context, JS::HandleObject global_object) {
- DCHECK(JS_IsGlobalObject(global_object));
-
- InterfaceData* interface_data = GetInterfaceData(context);
- if (!interface_data->interface_object) {
- InitializePrototypeAndInterfaceObject(
- interface_data, context, global_object);
- }
- DCHECK(interface_data->interface_object);
- return interface_data->interface_object;
-}
-
-
-namespace {
-} // namespace
-
-
-} // namespace testing
-} // namespace bindings
-} // namespace cobalt
-#endif // defined(NO_ENABLE_CONDITIONAL_INTERFACE)
diff --git a/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_disabled_interface.h b/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_disabled_interface.h
deleted file mode 100644
index 70574a4..0000000
--- a/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_disabled_interface.h
+++ /dev/null
@@ -1,56 +0,0 @@
-// Copyright 2017 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/mozjs/templates/interface.h.template
-
-#ifndef MozjsDisabledInterface_h
-#define MozjsDisabledInterface_h
-
-#if defined(NO_ENABLE_CONDITIONAL_INTERFACE)
-
-#include "base/hash_tables.h"
-#include "base/lazy_instance.h"
-#include "base/memory/ref_counted.h"
-#include "base/threading/thread_checker.h"
-#include "cobalt/base/polymorphic_downcast.h"
-#include "cobalt/script/wrappable.h"
-#include "cobalt/bindings/testing/disabled_interface.h"
-
-#include "third_party/mozjs/js/src/jsapi.h"
-
-namespace cobalt {
-namespace bindings {
-namespace testing {
-
-class MozjsDisabledInterface {
- public:
- static JSObject* CreateProxy(JSContext* context,
- const scoped_refptr<script::Wrappable>& wrappable);
- static const JSClass* PrototypeClass(JSContext* context);
- static JSObject* GetPrototype(JSContext* context,
- JS::HandleObject global_object);
- static JSObject* GetInterfaceObject(JSContext* context,
- JS::HandleObject global_object);
-};
-
-} // namespace testing
-} // namespace bindings
-} // namespace cobalt
-
-#endif // defined(NO_ENABLE_CONDITIONAL_INTERFACE)
-
-#endif // MozjsDisabledInterface_h
diff --git a/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_dom_string_test_interface.cc b/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_dom_string_test_interface.cc
deleted file mode 100644
index 68fa836..0000000
--- a/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_dom_string_test_interface.cc
+++ /dev/null
@@ -1,815 +0,0 @@
-// Copyright 2017 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/mozjs/templates/interface.cc.template
-
-#include "cobalt/bindings/testing/mozjs_dom_string_test_interface.h"
-
-#include "base/debug/trace_event.h"
-#include "cobalt/base/polymorphic_downcast.h"
-#include "cobalt/script/global_environment.h"
-#include "cobalt/script/opaque_handle.h"
-#include "cobalt/script/script_value.h"
-
-#include "mozjs_gen_type_conversion.h"
-
-#include "base/lazy_instance.h"
-#include "cobalt/script/exception_state.h"
-#include "cobalt/script/mozjs/callback_function_conversion.h"
-#include "cobalt/script/mozjs/conversion_helpers.h"
-#include "cobalt/script/mozjs/mozjs_callback_function.h"
-#include "cobalt/script/mozjs/mozjs_exception_state.h"
-#include "cobalt/script/mozjs/mozjs_global_environment.h"
-#include "cobalt/script/mozjs/mozjs_object_handle.h"
-#include "cobalt/script/mozjs/mozjs_property_enumerator.h"
-#include "cobalt/script/mozjs/mozjs_user_object_holder.h"
-#include "cobalt/script/mozjs/mozjs_value_handle.h"
-#include "cobalt/script/mozjs/native_promise.h"
-#include "cobalt/script/mozjs/proxy_handler.h"
-#include "cobalt/script/mozjs/type_traits.h"
-#include "cobalt/script/mozjs/wrapper_factory.h"
-#include "cobalt/script/mozjs/wrapper_private.h"
-#include "cobalt/script/property_enumerator.h"
-#include "cobalt/script/sequence.h"
-#include "third_party/mozjs/js/src/jsapi.h"
-#include "third_party/mozjs/js/src/jsfriendapi.h"
-
-namespace {
-using cobalt::bindings::testing::DOMStringTestInterface;
-using cobalt::bindings::testing::MozjsDOMStringTestInterface;
-using cobalt::script::CallbackInterfaceTraits;
-using cobalt::script::GlobalEnvironment;
-using cobalt::script::OpaqueHandle;
-using cobalt::script::OpaqueHandleHolder;
-using cobalt::script::ScriptValue;
-using cobalt::script::ValueHandle;
-using cobalt::script::Wrappable;
-
-using cobalt::script::CallbackFunction;
-using cobalt::script::CallbackInterfaceTraits;
-using cobalt::script::ExceptionState;
-using cobalt::script::Wrappable;
-using cobalt::script::mozjs::FromJSValue;
-using cobalt::script::mozjs::InterfaceData;
-using cobalt::script::mozjs::MozjsCallbackFunction;
-using cobalt::script::mozjs::MozjsExceptionState;
-using cobalt::script::mozjs::MozjsGlobalEnvironment;
-using cobalt::script::mozjs::MozjsPropertyEnumerator;
-using cobalt::script::mozjs::MozjsUserObjectHolder;
-using cobalt::script::mozjs::ProxyHandler;
-using cobalt::script::mozjs::ToJSValue;
-using cobalt::script::mozjs::TypeTraits;
-using cobalt::script::mozjs::WrapperFactory;
-using cobalt::script::mozjs::WrapperPrivate;
-using cobalt::script::mozjs::kConversionFlagClamped;
-using cobalt::script::mozjs::kConversionFlagNullable;
-using cobalt::script::mozjs::kConversionFlagRestricted;
-using cobalt::script::mozjs::kConversionFlagTreatNullAsEmptyString;
-using cobalt::script::mozjs::kConversionFlagTreatUndefinedAsEmptyString;
-using cobalt::script::mozjs::kNoConversionFlags;
-} // namespace
-
-namespace cobalt {
-namespace bindings {
-namespace testing {
-
-namespace {
-
-class MozjsDOMStringTestInterfaceHandler : public ProxyHandler {
- public:
- MozjsDOMStringTestInterfaceHandler()
- : ProxyHandler(indexed_property_hooks, named_property_hooks) {}
-
- private:
- static NamedPropertyHooks named_property_hooks;
- static IndexedPropertyHooks indexed_property_hooks;
-};
-
-ProxyHandler::NamedPropertyHooks
-MozjsDOMStringTestInterfaceHandler::named_property_hooks = {
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
-};
-ProxyHandler::IndexedPropertyHooks
-MozjsDOMStringTestInterfaceHandler::indexed_property_hooks = {
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
-};
-
-static base::LazyInstance<MozjsDOMStringTestInterfaceHandler>
- proxy_handler;
-
-JSBool HasInstance(JSContext *context, JS::HandleObject type,
- JS::MutableHandleValue vp, JSBool *success) {
- JS::RootedObject global_object(
- context, JS_GetGlobalForObject(context, type));
- DCHECK(global_object);
-
- JS::RootedObject prototype(
- context, MozjsDOMStringTestInterface::GetPrototype(context, global_object));
-
- // |IsDelegate| walks the prototype chain of an object returning true if
- // .prototype is found.
- bool is_delegate;
- if (!IsDelegate(context, prototype, vp, &is_delegate)) {
- *success = false;
- return false;
- }
-
- *success = is_delegate;
- return true;
-}
-
-InterfaceData* CreateCachedInterfaceData() {
- InterfaceData* interface_data = new InterfaceData();
- memset(&interface_data->instance_class_definition, 0,
- sizeof(interface_data->instance_class_definition));
- memset(&interface_data->prototype_class_definition, 0,
- sizeof(interface_data->prototype_class_definition));
- memset(&interface_data->interface_object_class_definition, 0,
- sizeof(interface_data->interface_object_class_definition));
-
- JSClass* instance_class = &interface_data->instance_class_definition;
- const int kGlobalFlags = 0;
- instance_class->name = "DOMStringTestInterface";
- instance_class->flags = kGlobalFlags | JSCLASS_HAS_PRIVATE;
- instance_class->addProperty = JS_PropertyStub;
- instance_class->delProperty = JS_DeletePropertyStub;
- instance_class->getProperty = JS_PropertyStub;
- instance_class->setProperty = JS_StrictPropertyStub;
- instance_class->enumerate = JS_EnumerateStub;
- instance_class->resolve = JS_ResolveStub;
- instance_class->convert = JS_ConvertStub;
- // Function to be called before on object of this class is garbage collected.
- instance_class->finalize = &WrapperPrivate::Finalizer;
- // Called to trace objects that can be referenced from this object.
- instance_class->trace = &WrapperPrivate::Trace;
-
- JSClass* prototype_class = &interface_data->prototype_class_definition;
- prototype_class->name = "DOMStringTestInterfacePrototype";
- prototype_class->flags = 0;
- prototype_class->addProperty = JS_PropertyStub;
- prototype_class->delProperty = JS_DeletePropertyStub;
- prototype_class->getProperty = JS_PropertyStub;
- prototype_class->setProperty = JS_StrictPropertyStub;
- prototype_class->enumerate = JS_EnumerateStub;
- prototype_class->resolve = JS_ResolveStub;
- prototype_class->convert = JS_ConvertStub;
-
- JSClass* interface_object_class =
- &interface_data->interface_object_class_definition;
- interface_object_class->name = "DOMStringTestInterfaceConstructor";
- interface_object_class->flags = 0;
- interface_object_class->addProperty = JS_PropertyStub;
- interface_object_class->delProperty = JS_DeletePropertyStub;
- interface_object_class->getProperty = JS_PropertyStub;
- interface_object_class->setProperty = JS_StrictPropertyStub;
- interface_object_class->enumerate = JS_EnumerateStub;
- interface_object_class->resolve = JS_ResolveStub;
- interface_object_class->convert = JS_ConvertStub;
- interface_object_class->hasInstance = &HasInstance;
- return interface_data;
-}
-
-JSBool get_property(
- JSContext* context, JS::HandleObject object, JS::HandleId id,
- JS::MutableHandleValue vp) {
- const JSClass* proto_class =
- MozjsDOMStringTestInterface::PrototypeClass(context);
- if (proto_class == JS_GetClass(object)) {
- // Simply returns true if the object is this class's prototype object.
- // There is no need to return any value due to the object is not a platform
- // object. The execution reaches here when Object.getOwnPropertyDescriptor
- // gets called on native object prototypes.
- return true;
- }
-
- MozjsGlobalEnvironment* global_environment =
- static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context));
- WrapperFactory* wrapper_factory = global_environment->wrapper_factory();
- if (!wrapper_factory->DoesObjectImplementInterface(
- object, base::GetTypeId<DOMStringTestInterface>())) {
- MozjsExceptionState exception(context);
- exception.SetSimpleException(script::kDoesNotImplementInterface);
- return false;
- }
- MozjsExceptionState exception_state(context);
- JS::RootedValue result_value(context);
-
- WrapperPrivate* wrapper_private =
- WrapperPrivate::GetFromObject(context, object);
- DOMStringTestInterface* impl =
- wrapper_private->wrappable<DOMStringTestInterface>().get();
-
- if (!exception_state.is_exception_set()) {
- ToJSValue(context,
- impl->property(),
- &result_value);
- }
- if (!exception_state.is_exception_set()) {
- vp.set(result_value);
- }
- return !exception_state.is_exception_set();
-}
-
-JSBool set_property(
- JSContext* context, JS::HandleObject object, JS::HandleId id,
- JSBool strict, JS::MutableHandleValue vp) {
- const JSClass* proto_class =
- MozjsDOMStringTestInterface::PrototypeClass(context);
- if (proto_class == JS_GetClass(object)) {
- // Simply returns true if the object is this class's prototype object.
- // There is no need to return any value due to the object is not a platform
- // object. The execution reaches here when Object.getOwnPropertyDescriptor
- // gets called on native object prototypes.
- return true;
- }
-
- MozjsGlobalEnvironment* global_environment =
- static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context));
- WrapperFactory* wrapper_factory = global_environment->wrapper_factory();
- if (!wrapper_factory->DoesObjectImplementInterface(
- object, base::GetTypeId<DOMStringTestInterface>())) {
- MozjsExceptionState exception(context);
- exception.SetSimpleException(script::kDoesNotImplementInterface);
- return false;
- }
- MozjsExceptionState exception_state(context);
- JS::RootedValue result_value(context);
-
- WrapperPrivate* wrapper_private =
- WrapperPrivate::GetFromObject(context, object);
- DOMStringTestInterface* impl =
- wrapper_private->wrappable<DOMStringTestInterface>().get();
- TypeTraits<std::string >::ConversionType value;
- FromJSValue(context, vp, kNoConversionFlags, &exception_state,
- &value);
- if (exception_state.is_exception_set()) {
- return false;
- }
-
- impl->set_property(value);
- result_value.set(JS::UndefinedHandleValue);
- return !exception_state.is_exception_set();
-}
-
-JSBool get_readOnlyProperty(
- JSContext* context, JS::HandleObject object, JS::HandleId id,
- JS::MutableHandleValue vp) {
- const JSClass* proto_class =
- MozjsDOMStringTestInterface::PrototypeClass(context);
- if (proto_class == JS_GetClass(object)) {
- // Simply returns true if the object is this class's prototype object.
- // There is no need to return any value due to the object is not a platform
- // object. The execution reaches here when Object.getOwnPropertyDescriptor
- // gets called on native object prototypes.
- return true;
- }
-
- MozjsGlobalEnvironment* global_environment =
- static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context));
- WrapperFactory* wrapper_factory = global_environment->wrapper_factory();
- if (!wrapper_factory->DoesObjectImplementInterface(
- object, base::GetTypeId<DOMStringTestInterface>())) {
- MozjsExceptionState exception(context);
- exception.SetSimpleException(script::kDoesNotImplementInterface);
- return false;
- }
- MozjsExceptionState exception_state(context);
- JS::RootedValue result_value(context);
-
- WrapperPrivate* wrapper_private =
- WrapperPrivate::GetFromObject(context, object);
- DOMStringTestInterface* impl =
- wrapper_private->wrappable<DOMStringTestInterface>().get();
-
- if (!exception_state.is_exception_set()) {
- ToJSValue(context,
- impl->read_only_property(),
- &result_value);
- }
- if (!exception_state.is_exception_set()) {
- vp.set(result_value);
- }
- return !exception_state.is_exception_set();
-}
-
-JSBool get_readOnlyTokenProperty(
- JSContext* context, JS::HandleObject object, JS::HandleId id,
- JS::MutableHandleValue vp) {
- const JSClass* proto_class =
- MozjsDOMStringTestInterface::PrototypeClass(context);
- if (proto_class == JS_GetClass(object)) {
- // Simply returns true if the object is this class's prototype object.
- // There is no need to return any value due to the object is not a platform
- // object. The execution reaches here when Object.getOwnPropertyDescriptor
- // gets called on native object prototypes.
- return true;
- }
-
- MozjsGlobalEnvironment* global_environment =
- static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context));
- WrapperFactory* wrapper_factory = global_environment->wrapper_factory();
- if (!wrapper_factory->DoesObjectImplementInterface(
- object, base::GetTypeId<DOMStringTestInterface>())) {
- MozjsExceptionState exception(context);
- exception.SetSimpleException(script::kDoesNotImplementInterface);
- return false;
- }
- MozjsExceptionState exception_state(context);
- JS::RootedValue result_value(context);
-
- WrapperPrivate* wrapper_private =
- WrapperPrivate::GetFromObject(context, object);
- DOMStringTestInterface* impl =
- wrapper_private->wrappable<DOMStringTestInterface>().get();
-
- if (!exception_state.is_exception_set()) {
- ToJSValue(context,
- impl->read_only_token_property(),
- &result_value);
- }
- if (!exception_state.is_exception_set()) {
- vp.set(result_value);
- }
- return !exception_state.is_exception_set();
-}
-
-JSBool get_nullIsEmptyProperty(
- JSContext* context, JS::HandleObject object, JS::HandleId id,
- JS::MutableHandleValue vp) {
- const JSClass* proto_class =
- MozjsDOMStringTestInterface::PrototypeClass(context);
- if (proto_class == JS_GetClass(object)) {
- // Simply returns true if the object is this class's prototype object.
- // There is no need to return any value due to the object is not a platform
- // object. The execution reaches here when Object.getOwnPropertyDescriptor
- // gets called on native object prototypes.
- return true;
- }
-
- MozjsGlobalEnvironment* global_environment =
- static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context));
- WrapperFactory* wrapper_factory = global_environment->wrapper_factory();
- if (!wrapper_factory->DoesObjectImplementInterface(
- object, base::GetTypeId<DOMStringTestInterface>())) {
- MozjsExceptionState exception(context);
- exception.SetSimpleException(script::kDoesNotImplementInterface);
- return false;
- }
- MozjsExceptionState exception_state(context);
- JS::RootedValue result_value(context);
-
- WrapperPrivate* wrapper_private =
- WrapperPrivate::GetFromObject(context, object);
- DOMStringTestInterface* impl =
- wrapper_private->wrappable<DOMStringTestInterface>().get();
-
- if (!exception_state.is_exception_set()) {
- ToJSValue(context,
- impl->null_is_empty_property(),
- &result_value);
- }
- if (!exception_state.is_exception_set()) {
- vp.set(result_value);
- }
- return !exception_state.is_exception_set();
-}
-
-JSBool set_nullIsEmptyProperty(
- JSContext* context, JS::HandleObject object, JS::HandleId id,
- JSBool strict, JS::MutableHandleValue vp) {
- const JSClass* proto_class =
- MozjsDOMStringTestInterface::PrototypeClass(context);
- if (proto_class == JS_GetClass(object)) {
- // Simply returns true if the object is this class's prototype object.
- // There is no need to return any value due to the object is not a platform
- // object. The execution reaches here when Object.getOwnPropertyDescriptor
- // gets called on native object prototypes.
- return true;
- }
-
- MozjsGlobalEnvironment* global_environment =
- static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context));
- WrapperFactory* wrapper_factory = global_environment->wrapper_factory();
- if (!wrapper_factory->DoesObjectImplementInterface(
- object, base::GetTypeId<DOMStringTestInterface>())) {
- MozjsExceptionState exception(context);
- exception.SetSimpleException(script::kDoesNotImplementInterface);
- return false;
- }
- MozjsExceptionState exception_state(context);
- JS::RootedValue result_value(context);
-
- WrapperPrivate* wrapper_private =
- WrapperPrivate::GetFromObject(context, object);
- DOMStringTestInterface* impl =
- wrapper_private->wrappable<DOMStringTestInterface>().get();
- TypeTraits<std::string >::ConversionType value;
- FromJSValue(context, vp, (kConversionFlagTreatNullAsEmptyString), &exception_state,
- &value);
- if (exception_state.is_exception_set()) {
- return false;
- }
-
- impl->set_null_is_empty_property(value);
- result_value.set(JS::UndefinedHandleValue);
- return !exception_state.is_exception_set();
-}
-
-JSBool get_undefinedIsEmptyProperty(
- JSContext* context, JS::HandleObject object, JS::HandleId id,
- JS::MutableHandleValue vp) {
- const JSClass* proto_class =
- MozjsDOMStringTestInterface::PrototypeClass(context);
- if (proto_class == JS_GetClass(object)) {
- // Simply returns true if the object is this class's prototype object.
- // There is no need to return any value due to the object is not a platform
- // object. The execution reaches here when Object.getOwnPropertyDescriptor
- // gets called on native object prototypes.
- return true;
- }
-
- MozjsGlobalEnvironment* global_environment =
- static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context));
- WrapperFactory* wrapper_factory = global_environment->wrapper_factory();
- if (!wrapper_factory->DoesObjectImplementInterface(
- object, base::GetTypeId<DOMStringTestInterface>())) {
- MozjsExceptionState exception(context);
- exception.SetSimpleException(script::kDoesNotImplementInterface);
- return false;
- }
- MozjsExceptionState exception_state(context);
- JS::RootedValue result_value(context);
-
- WrapperPrivate* wrapper_private =
- WrapperPrivate::GetFromObject(context, object);
- DOMStringTestInterface* impl =
- wrapper_private->wrappable<DOMStringTestInterface>().get();
-
- if (!exception_state.is_exception_set()) {
- ToJSValue(context,
- impl->undefined_is_empty_property(),
- &result_value);
- }
- if (!exception_state.is_exception_set()) {
- vp.set(result_value);
- }
- return !exception_state.is_exception_set();
-}
-
-JSBool set_undefinedIsEmptyProperty(
- JSContext* context, JS::HandleObject object, JS::HandleId id,
- JSBool strict, JS::MutableHandleValue vp) {
- const JSClass* proto_class =
- MozjsDOMStringTestInterface::PrototypeClass(context);
- if (proto_class == JS_GetClass(object)) {
- // Simply returns true if the object is this class's prototype object.
- // There is no need to return any value due to the object is not a platform
- // object. The execution reaches here when Object.getOwnPropertyDescriptor
- // gets called on native object prototypes.
- return true;
- }
-
- MozjsGlobalEnvironment* global_environment =
- static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context));
- WrapperFactory* wrapper_factory = global_environment->wrapper_factory();
- if (!wrapper_factory->DoesObjectImplementInterface(
- object, base::GetTypeId<DOMStringTestInterface>())) {
- MozjsExceptionState exception(context);
- exception.SetSimpleException(script::kDoesNotImplementInterface);
- return false;
- }
- MozjsExceptionState exception_state(context);
- JS::RootedValue result_value(context);
-
- WrapperPrivate* wrapper_private =
- WrapperPrivate::GetFromObject(context, object);
- DOMStringTestInterface* impl =
- wrapper_private->wrappable<DOMStringTestInterface>().get();
- TypeTraits<std::string >::ConversionType value;
- FromJSValue(context, vp, (kConversionFlagTreatUndefinedAsEmptyString), &exception_state,
- &value);
- if (exception_state.is_exception_set()) {
- return false;
- }
-
- impl->set_undefined_is_empty_property(value);
- result_value.set(JS::UndefinedHandleValue);
- return !exception_state.is_exception_set();
-}
-
-JSBool get_nullableUndefinedIsEmptyProperty(
- JSContext* context, JS::HandleObject object, JS::HandleId id,
- JS::MutableHandleValue vp) {
- const JSClass* proto_class =
- MozjsDOMStringTestInterface::PrototypeClass(context);
- if (proto_class == JS_GetClass(object)) {
- // Simply returns true if the object is this class's prototype object.
- // There is no need to return any value due to the object is not a platform
- // object. The execution reaches here when Object.getOwnPropertyDescriptor
- // gets called on native object prototypes.
- return true;
- }
-
- MozjsGlobalEnvironment* global_environment =
- static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context));
- WrapperFactory* wrapper_factory = global_environment->wrapper_factory();
- if (!wrapper_factory->DoesObjectImplementInterface(
- object, base::GetTypeId<DOMStringTestInterface>())) {
- MozjsExceptionState exception(context);
- exception.SetSimpleException(script::kDoesNotImplementInterface);
- return false;
- }
- MozjsExceptionState exception_state(context);
- JS::RootedValue result_value(context);
-
- WrapperPrivate* wrapper_private =
- WrapperPrivate::GetFromObject(context, object);
- DOMStringTestInterface* impl =
- wrapper_private->wrappable<DOMStringTestInterface>().get();
-
- if (!exception_state.is_exception_set()) {
- ToJSValue(context,
- impl->nullable_undefined_is_empty_property(),
- &result_value);
- }
- if (!exception_state.is_exception_set()) {
- vp.set(result_value);
- }
- return !exception_state.is_exception_set();
-}
-
-JSBool set_nullableUndefinedIsEmptyProperty(
- JSContext* context, JS::HandleObject object, JS::HandleId id,
- JSBool strict, JS::MutableHandleValue vp) {
- const JSClass* proto_class =
- MozjsDOMStringTestInterface::PrototypeClass(context);
- if (proto_class == JS_GetClass(object)) {
- // Simply returns true if the object is this class's prototype object.
- // There is no need to return any value due to the object is not a platform
- // object. The execution reaches here when Object.getOwnPropertyDescriptor
- // gets called on native object prototypes.
- return true;
- }
-
- MozjsGlobalEnvironment* global_environment =
- static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context));
- WrapperFactory* wrapper_factory = global_environment->wrapper_factory();
- if (!wrapper_factory->DoesObjectImplementInterface(
- object, base::GetTypeId<DOMStringTestInterface>())) {
- MozjsExceptionState exception(context);
- exception.SetSimpleException(script::kDoesNotImplementInterface);
- return false;
- }
- MozjsExceptionState exception_state(context);
- JS::RootedValue result_value(context);
-
- WrapperPrivate* wrapper_private =
- WrapperPrivate::GetFromObject(context, object);
- DOMStringTestInterface* impl =
- wrapper_private->wrappable<DOMStringTestInterface>().get();
- TypeTraits<base::optional<std::string > >::ConversionType value;
- FromJSValue(context, vp, (kConversionFlagNullable | kConversionFlagTreatUndefinedAsEmptyString), &exception_state,
- &value);
- if (exception_state.is_exception_set()) {
- return false;
- }
-
- impl->set_nullable_undefined_is_empty_property(value);
- result_value.set(JS::UndefinedHandleValue);
- return !exception_state.is_exception_set();
-}
-
-
-const JSPropertySpec prototype_properties[] = {
- { // Read/Write property
- "property", 0,
- JSPROP_SHARED | JSPROP_ENUMERATE,
- JSOP_WRAPPER(&get_property),
- JSOP_WRAPPER(&set_property),
- },
- { // Readonly attribute
- "readOnlyProperty", 0,
- JSPROP_SHARED | JSPROP_ENUMERATE | JSPROP_READONLY,
- JSOP_WRAPPER(&get_readOnlyProperty),
- JSOP_NULLWRAPPER,
- },
- { // Readonly attribute
- "readOnlyTokenProperty", 0,
- JSPROP_SHARED | JSPROP_ENUMERATE | JSPROP_READONLY,
- JSOP_WRAPPER(&get_readOnlyTokenProperty),
- JSOP_NULLWRAPPER,
- },
- { // Read/Write property
- "nullIsEmptyProperty", 0,
- JSPROP_SHARED | JSPROP_ENUMERATE,
- JSOP_WRAPPER(&get_nullIsEmptyProperty),
- JSOP_WRAPPER(&set_nullIsEmptyProperty),
- },
- { // Read/Write property
- "undefinedIsEmptyProperty", 0,
- JSPROP_SHARED | JSPROP_ENUMERATE,
- JSOP_WRAPPER(&get_undefinedIsEmptyProperty),
- JSOP_WRAPPER(&set_undefinedIsEmptyProperty),
- },
- { // Read/Write property
- "nullableUndefinedIsEmptyProperty", 0,
- JSPROP_SHARED | JSPROP_ENUMERATE,
- JSOP_WRAPPER(&get_nullableUndefinedIsEmptyProperty),
- JSOP_WRAPPER(&set_nullableUndefinedIsEmptyProperty),
- },
- JS_PS_END
-};
-
-const JSFunctionSpec prototype_functions[] = {
- JS_FS_END
-};
-
-const JSPropertySpec interface_object_properties[] = {
- JS_PS_END
-};
-
-const JSFunctionSpec interface_object_functions[] = {
- JS_FS_END
-};
-
-const JSPropertySpec own_properties[] = {
- JS_PS_END
-};
-
-void InitializePrototypeAndInterfaceObject(
- InterfaceData* interface_data, JSContext* context,
- JS::HandleObject global_object) {
- DCHECK(!interface_data->prototype);
- DCHECK(!interface_data->interface_object);
- DCHECK(JS_IsGlobalObject(global_object));
-
- JS::RootedObject parent_prototype(
- context, JS_GetObjectPrototype(context, global_object));
- DCHECK(parent_prototype);
-
- // Create the Prototype object.
- interface_data->prototype = JS_NewObjectWithGivenProto(
- context, &interface_data->prototype_class_definition, parent_prototype,
- NULL);
- bool success = JS_DefineProperties(
- context, interface_data->prototype, prototype_properties);
- DCHECK(success);
- success = JS_DefineFunctions(
- context, interface_data->prototype, prototype_functions);
- DCHECK(success);
-
- JS::RootedObject function_prototype(
- context, JS_GetFunctionPrototype(context, global_object));
- DCHECK(function_prototype);
- // Create the Interface object.
- interface_data->interface_object = JS_NewObjectWithGivenProto(
- context, &interface_data->interface_object_class_definition,
- function_prototype, NULL);
-
- // Add the InterfaceObject.name property.
- JS::RootedObject rooted_interface_object(
- context, interface_data->interface_object);
- JS::RootedValue name_value(context);
- const char name[] =
- "DOMStringTestInterface";
- name_value.setString(JS_NewStringCopyZ(context, name));
- success =
- JS_DefineProperty(context, rooted_interface_object, "name", name_value,
- JS_PropertyStub, JS_StrictPropertyStub,
- JSPROP_READONLY);
- DCHECK(success);
-
- // Define interface object properties (including constants).
- success = JS_DefineProperties(context, rooted_interface_object,
- interface_object_properties);
- DCHECK(success);
- // Define interface object functions (static).
- success = JS_DefineFunctions(context, rooted_interface_object,
- interface_object_functions);
- DCHECK(success);
-
-
- // Set the Prototype.constructor and Constructor.prototype properties.
- DCHECK(interface_data->interface_object);
- DCHECK(interface_data->prototype);
- JS::RootedObject rooted_prototype(context, interface_data->prototype);
- success = JS_LinkConstructorAndPrototype(
- context,
- rooted_interface_object,
- rooted_prototype);
- DCHECK(success);
-}
-
-InterfaceData* GetInterfaceData(JSContext* context) {
- MozjsGlobalEnvironment* global_environment =
- static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context));
- // Use the address of the properties definition for this interface as a
- // unique key for looking up the InterfaceData for this interface.
- intptr_t key = reinterpret_cast<intptr_t>(&own_properties);
- InterfaceData* interface_data = global_environment->GetInterfaceData(key);
- if (!interface_data) {
- interface_data = CreateCachedInterfaceData();
- DCHECK(interface_data);
- global_environment->CacheInterfaceData(key, interface_data);
- DCHECK_EQ(interface_data, global_environment->GetInterfaceData(key));
- }
- return interface_data;
-}
-
-} // namespace
-
-// static
-JSObject* MozjsDOMStringTestInterface::CreateProxy(
- JSContext* context, const scoped_refptr<Wrappable>& wrappable) {
- DCHECK(MozjsGlobalEnvironment::GetFromContext(context));
- JS::RootedObject global_object(
- context,
- MozjsGlobalEnvironment::GetFromContext(context)->global_object());
- DCHECK(global_object);
-
- InterfaceData* interface_data = GetInterfaceData(context);
- JS::RootedObject prototype(context, GetPrototype(context, global_object));
- DCHECK(prototype);
- JS::RootedObject new_object(context, JS_NewObjectWithGivenProto(
- context, &interface_data->instance_class_definition, prototype, NULL));
- DCHECK(new_object);
- JS::RootedObject proxy(context,
- ProxyHandler::NewProxy(context, new_object, prototype, NULL,
- proxy_handler.Pointer()));
- WrapperPrivate::AddPrivateData(context, proxy, wrappable);
- return proxy;
-}
-
-//static
-const JSClass* MozjsDOMStringTestInterface::PrototypeClass(
- JSContext* context) {
- DCHECK(MozjsGlobalEnvironment::GetFromContext(context));
- JS::RootedObject global_object(
- context,
- MozjsGlobalEnvironment::GetFromContext(context)->global_object());
- DCHECK(global_object);
-
- JS::RootedObject prototype(context, GetPrototype(context, global_object));
- JSClass* proto_class = JS_GetClass(*prototype.address());
- return proto_class;
-}
-
-// static
-JSObject* MozjsDOMStringTestInterface::GetPrototype(
- JSContext* context, JS::HandleObject global_object) {
- DCHECK(JS_IsGlobalObject(global_object));
-
- InterfaceData* interface_data = GetInterfaceData(context);
- if (!interface_data->prototype) {
- // Create new prototype that has all the props and methods
- InitializePrototypeAndInterfaceObject(
- interface_data, context, global_object);
- }
- DCHECK(interface_data->prototype);
- return interface_data->prototype;
-}
-
-// static
-JSObject* MozjsDOMStringTestInterface::GetInterfaceObject(
- JSContext* context, JS::HandleObject global_object) {
- DCHECK(JS_IsGlobalObject(global_object));
-
- InterfaceData* interface_data = GetInterfaceData(context);
- if (!interface_data->interface_object) {
- InitializePrototypeAndInterfaceObject(
- interface_data, context, global_object);
- }
- DCHECK(interface_data->interface_object);
- return interface_data->interface_object;
-}
-
-
-namespace {
-} // namespace
-
-
-} // namespace testing
-} // namespace bindings
-} // namespace cobalt
diff --git a/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_dom_string_test_interface.h b/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_dom_string_test_interface.h
deleted file mode 100644
index 8145570..0000000
--- a/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_dom_string_test_interface.h
+++ /dev/null
@@ -1,52 +0,0 @@
-// Copyright 2017 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/mozjs/templates/interface.h.template
-
-#ifndef MozjsDOMStringTestInterface_h
-#define MozjsDOMStringTestInterface_h
-
-#include "base/hash_tables.h"
-#include "base/lazy_instance.h"
-#include "base/memory/ref_counted.h"
-#include "base/threading/thread_checker.h"
-#include "cobalt/base/polymorphic_downcast.h"
-#include "cobalt/script/wrappable.h"
-#include "cobalt/bindings/testing/dom_string_test_interface.h"
-
-#include "third_party/mozjs/js/src/jsapi.h"
-
-namespace cobalt {
-namespace bindings {
-namespace testing {
-
-class MozjsDOMStringTestInterface {
- public:
- static JSObject* CreateProxy(JSContext* context,
- const scoped_refptr<script::Wrappable>& wrappable);
- static const JSClass* PrototypeClass(JSContext* context);
- static JSObject* GetPrototype(JSContext* context,
- JS::HandleObject global_object);
- static JSObject* GetInterfaceObject(JSContext* context,
- JS::HandleObject global_object);
-};
-
-} // namespace testing
-} // namespace bindings
-} // namespace cobalt
-
-#endif // MozjsDOMStringTestInterface_h
diff --git a/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_enumeration_interface.cc b/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_enumeration_interface.cc
deleted file mode 100644
index 17e8569..0000000
--- a/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_enumeration_interface.cc
+++ /dev/null
@@ -1,553 +0,0 @@
-// Copyright 2017 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/mozjs/templates/interface.cc.template
-
-#include "cobalt/bindings/testing/mozjs_enumeration_interface.h"
-
-#include "base/debug/trace_event.h"
-#include "cobalt/base/polymorphic_downcast.h"
-#include "cobalt/script/global_environment.h"
-#include "cobalt/script/opaque_handle.h"
-#include "cobalt/script/script_value.h"
-#include "cobalt/bindings/testing/test_enum.h"
-
-#include "mozjs_gen_type_conversion.h"
-
-#include "base/lazy_instance.h"
-#include "cobalt/script/exception_state.h"
-#include "cobalt/script/mozjs/callback_function_conversion.h"
-#include "cobalt/script/mozjs/conversion_helpers.h"
-#include "cobalt/script/mozjs/mozjs_callback_function.h"
-#include "cobalt/script/mozjs/mozjs_exception_state.h"
-#include "cobalt/script/mozjs/mozjs_global_environment.h"
-#include "cobalt/script/mozjs/mozjs_object_handle.h"
-#include "cobalt/script/mozjs/mozjs_property_enumerator.h"
-#include "cobalt/script/mozjs/mozjs_user_object_holder.h"
-#include "cobalt/script/mozjs/mozjs_value_handle.h"
-#include "cobalt/script/mozjs/native_promise.h"
-#include "cobalt/script/mozjs/proxy_handler.h"
-#include "cobalt/script/mozjs/type_traits.h"
-#include "cobalt/script/mozjs/wrapper_factory.h"
-#include "cobalt/script/mozjs/wrapper_private.h"
-#include "cobalt/script/property_enumerator.h"
-#include "cobalt/script/sequence.h"
-#include "third_party/mozjs/js/src/jsapi.h"
-#include "third_party/mozjs/js/src/jsfriendapi.h"
-
-namespace {
-using cobalt::bindings::testing::EnumerationInterface;
-using cobalt::bindings::testing::MozjsEnumerationInterface;
-using cobalt::bindings::testing::TestEnum;
-using cobalt::script::CallbackInterfaceTraits;
-using cobalt::script::GlobalEnvironment;
-using cobalt::script::OpaqueHandle;
-using cobalt::script::OpaqueHandleHolder;
-using cobalt::script::ScriptValue;
-using cobalt::script::ValueHandle;
-using cobalt::script::Wrappable;
-
-using cobalt::script::CallbackFunction;
-using cobalt::script::CallbackInterfaceTraits;
-using cobalt::script::ExceptionState;
-using cobalt::script::Wrappable;
-using cobalt::script::mozjs::FromJSValue;
-using cobalt::script::mozjs::InterfaceData;
-using cobalt::script::mozjs::MozjsCallbackFunction;
-using cobalt::script::mozjs::MozjsExceptionState;
-using cobalt::script::mozjs::MozjsGlobalEnvironment;
-using cobalt::script::mozjs::MozjsPropertyEnumerator;
-using cobalt::script::mozjs::MozjsUserObjectHolder;
-using cobalt::script::mozjs::ProxyHandler;
-using cobalt::script::mozjs::ToJSValue;
-using cobalt::script::mozjs::TypeTraits;
-using cobalt::script::mozjs::WrapperFactory;
-using cobalt::script::mozjs::WrapperPrivate;
-using cobalt::script::mozjs::kConversionFlagClamped;
-using cobalt::script::mozjs::kConversionFlagNullable;
-using cobalt::script::mozjs::kConversionFlagRestricted;
-using cobalt::script::mozjs::kConversionFlagTreatNullAsEmptyString;
-using cobalt::script::mozjs::kConversionFlagTreatUndefinedAsEmptyString;
-using cobalt::script::mozjs::kNoConversionFlags;
-} // namespace
-
-namespace cobalt {
-namespace bindings {
-namespace testing {
-
-namespace {
-
-class MozjsEnumerationInterfaceHandler : public ProxyHandler {
- public:
- MozjsEnumerationInterfaceHandler()
- : ProxyHandler(indexed_property_hooks, named_property_hooks) {}
-
- private:
- static NamedPropertyHooks named_property_hooks;
- static IndexedPropertyHooks indexed_property_hooks;
-};
-
-ProxyHandler::NamedPropertyHooks
-MozjsEnumerationInterfaceHandler::named_property_hooks = {
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
-};
-ProxyHandler::IndexedPropertyHooks
-MozjsEnumerationInterfaceHandler::indexed_property_hooks = {
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
-};
-
-static base::LazyInstance<MozjsEnumerationInterfaceHandler>
- proxy_handler;
-
-JSBool Constructor(JSContext* context, unsigned int argc, JS::Value* vp);
-JSBool HasInstance(JSContext *context, JS::HandleObject type,
- JS::MutableHandleValue vp, JSBool *success) {
- JS::RootedObject global_object(
- context, JS_GetGlobalForObject(context, type));
- DCHECK(global_object);
-
- JS::RootedObject prototype(
- context, MozjsEnumerationInterface::GetPrototype(context, global_object));
-
- // |IsDelegate| walks the prototype chain of an object returning true if
- // .prototype is found.
- bool is_delegate;
- if (!IsDelegate(context, prototype, vp, &is_delegate)) {
- *success = false;
- return false;
- }
-
- *success = is_delegate;
- return true;
-}
-
-InterfaceData* CreateCachedInterfaceData() {
- InterfaceData* interface_data = new InterfaceData();
- memset(&interface_data->instance_class_definition, 0,
- sizeof(interface_data->instance_class_definition));
- memset(&interface_data->prototype_class_definition, 0,
- sizeof(interface_data->prototype_class_definition));
- memset(&interface_data->interface_object_class_definition, 0,
- sizeof(interface_data->interface_object_class_definition));
-
- JSClass* instance_class = &interface_data->instance_class_definition;
- const int kGlobalFlags = 0;
- instance_class->name = "EnumerationInterface";
- instance_class->flags = kGlobalFlags | JSCLASS_HAS_PRIVATE;
- instance_class->addProperty = JS_PropertyStub;
- instance_class->delProperty = JS_DeletePropertyStub;
- instance_class->getProperty = JS_PropertyStub;
- instance_class->setProperty = JS_StrictPropertyStub;
- instance_class->enumerate = JS_EnumerateStub;
- instance_class->resolve = JS_ResolveStub;
- instance_class->convert = JS_ConvertStub;
- // Function to be called before on object of this class is garbage collected.
- instance_class->finalize = &WrapperPrivate::Finalizer;
- // Called to trace objects that can be referenced from this object.
- instance_class->trace = &WrapperPrivate::Trace;
-
- JSClass* prototype_class = &interface_data->prototype_class_definition;
- prototype_class->name = "EnumerationInterfacePrototype";
- prototype_class->flags = 0;
- prototype_class->addProperty = JS_PropertyStub;
- prototype_class->delProperty = JS_DeletePropertyStub;
- prototype_class->getProperty = JS_PropertyStub;
- prototype_class->setProperty = JS_StrictPropertyStub;
- prototype_class->enumerate = JS_EnumerateStub;
- prototype_class->resolve = JS_ResolveStub;
- prototype_class->convert = JS_ConvertStub;
-
- JSClass* interface_object_class =
- &interface_data->interface_object_class_definition;
- interface_object_class->name = "EnumerationInterfaceConstructor";
- interface_object_class->flags = 0;
- interface_object_class->addProperty = JS_PropertyStub;
- interface_object_class->delProperty = JS_DeletePropertyStub;
- interface_object_class->getProperty = JS_PropertyStub;
- interface_object_class->setProperty = JS_StrictPropertyStub;
- interface_object_class->enumerate = JS_EnumerateStub;
- interface_object_class->resolve = JS_ResolveStub;
- interface_object_class->convert = JS_ConvertStub;
- interface_object_class->hasInstance = &HasInstance;
- interface_object_class->construct = Constructor;
- return interface_data;
-}
-
-JSBool get_enumProperty(
- JSContext* context, JS::HandleObject object, JS::HandleId id,
- JS::MutableHandleValue vp) {
- const JSClass* proto_class =
- MozjsEnumerationInterface::PrototypeClass(context);
- if (proto_class == JS_GetClass(object)) {
- // Simply returns true if the object is this class's prototype object.
- // There is no need to return any value due to the object is not a platform
- // object. The execution reaches here when Object.getOwnPropertyDescriptor
- // gets called on native object prototypes.
- return true;
- }
-
- MozjsGlobalEnvironment* global_environment =
- static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context));
- WrapperFactory* wrapper_factory = global_environment->wrapper_factory();
- if (!wrapper_factory->DoesObjectImplementInterface(
- object, base::GetTypeId<EnumerationInterface>())) {
- MozjsExceptionState exception(context);
- exception.SetSimpleException(script::kDoesNotImplementInterface);
- return false;
- }
- MozjsExceptionState exception_state(context);
- JS::RootedValue result_value(context);
-
- WrapperPrivate* wrapper_private =
- WrapperPrivate::GetFromObject(context, object);
- EnumerationInterface* impl =
- wrapper_private->wrappable<EnumerationInterface>().get();
-
- if (!exception_state.is_exception_set()) {
- ToJSValue(context,
- impl->enum_property(),
- &result_value);
- }
- if (!exception_state.is_exception_set()) {
- vp.set(result_value);
- }
- return !exception_state.is_exception_set();
-}
-
-JSBool set_enumProperty(
- JSContext* context, JS::HandleObject object, JS::HandleId id,
- JSBool strict, JS::MutableHandleValue vp) {
- const JSClass* proto_class =
- MozjsEnumerationInterface::PrototypeClass(context);
- if (proto_class == JS_GetClass(object)) {
- // Simply returns true if the object is this class's prototype object.
- // There is no need to return any value due to the object is not a platform
- // object. The execution reaches here when Object.getOwnPropertyDescriptor
- // gets called on native object prototypes.
- return true;
- }
-
- MozjsGlobalEnvironment* global_environment =
- static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context));
- WrapperFactory* wrapper_factory = global_environment->wrapper_factory();
- if (!wrapper_factory->DoesObjectImplementInterface(
- object, base::GetTypeId<EnumerationInterface>())) {
- MozjsExceptionState exception(context);
- exception.SetSimpleException(script::kDoesNotImplementInterface);
- return false;
- }
- MozjsExceptionState exception_state(context);
- JS::RootedValue result_value(context);
-
- WrapperPrivate* wrapper_private =
- WrapperPrivate::GetFromObject(context, object);
- EnumerationInterface* impl =
- wrapper_private->wrappable<EnumerationInterface>().get();
- TypeTraits<TestEnum >::ConversionType value;
- FromJSValue(context, vp, kNoConversionFlags, &exception_state,
- &value);
- if (exception_state.is_exception_set()) {
- return false;
- }
-
- impl->set_enum_property(value);
- result_value.set(JS::UndefinedHandleValue);
- return !exception_state.is_exception_set();
-}
-
-JSBool fcn_optionalEnumWithDefault(
- JSContext* context, uint32_t argc, JS::Value *vp) {
- JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
- // Compute the 'this' value.
- JS::RootedValue this_value(context, JS_ComputeThis(context, vp));
- // 'this' should be an object.
- JS::RootedObject object(context);
- if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) {
- return false;
- }
- if (!JS_ValueToObject(context, this_value, object.address())) {
- NOTREACHED();
- return false;
- }
- const JSClass* proto_class =
- MozjsEnumerationInterface::PrototypeClass(context);
- if (proto_class == JS_GetClass(object)) {
- // Simply returns true if the object is this class's prototype object.
- // There is no need to return any value due to the object is not a platform
- // object. The execution reaches here when Object.getOwnPropertyDescriptor
- // gets called on native object prototypes.
- return true;
- }
-
- MozjsGlobalEnvironment* global_environment =
- static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context));
- WrapperFactory* wrapper_factory = global_environment->wrapper_factory();
- if (!wrapper_factory->DoesObjectImplementInterface(
- object, base::GetTypeId<EnumerationInterface>())) {
- MozjsExceptionState exception(context);
- exception.SetSimpleException(script::kDoesNotImplementInterface);
- return false;
- }
- MozjsExceptionState exception_state(context);
- JS::RootedValue result_value(context);
-
- WrapperPrivate* wrapper_private =
- WrapperPrivate::GetFromObject(context, object);
- EnumerationInterface* impl =
- wrapper_private->wrappable<EnumerationInterface>().get();
- // Optional arguments with default values
- TypeTraits<TestEnum >::ConversionType value =
- kTestEnumBeta;
- size_t num_set_arguments = 1;
- if (args.length() > 0) {
- JS::RootedValue optional_value0(
- context, args[0]);
- FromJSValue(context,
- optional_value0,
- kNoConversionFlags,
- &exception_state,
- &value);
- if (exception_state.is_exception_set()) {
- return false;
- }
- }
-
- impl->OptionalEnumWithDefault(value);
- result_value.set(JS::UndefinedHandleValue);
- return !exception_state.is_exception_set();
-}
-
-
-const JSPropertySpec prototype_properties[] = {
- { // Read/Write property
- "enumProperty", 0,
- JSPROP_SHARED | JSPROP_ENUMERATE,
- JSOP_WRAPPER(&get_enumProperty),
- JSOP_WRAPPER(&set_enumProperty),
- },
- JS_PS_END
-};
-
-const JSFunctionSpec prototype_functions[] = {
- {
- "optionalEnumWithDefault",
- JSOP_WRAPPER(&fcn_optionalEnumWithDefault),
- 0,
- JSPROP_ENUMERATE,
- NULL,
- },
- JS_FS_END
-};
-
-const JSPropertySpec interface_object_properties[] = {
- JS_PS_END
-};
-
-const JSFunctionSpec interface_object_functions[] = {
- JS_FS_END
-};
-
-const JSPropertySpec own_properties[] = {
- JS_PS_END
-};
-
-void InitializePrototypeAndInterfaceObject(
- InterfaceData* interface_data, JSContext* context,
- JS::HandleObject global_object) {
- DCHECK(!interface_data->prototype);
- DCHECK(!interface_data->interface_object);
- DCHECK(JS_IsGlobalObject(global_object));
-
- JS::RootedObject parent_prototype(
- context, JS_GetObjectPrototype(context, global_object));
- DCHECK(parent_prototype);
-
- // Create the Prototype object.
- interface_data->prototype = JS_NewObjectWithGivenProto(
- context, &interface_data->prototype_class_definition, parent_prototype,
- NULL);
- bool success = JS_DefineProperties(
- context, interface_data->prototype, prototype_properties);
- DCHECK(success);
- success = JS_DefineFunctions(
- context, interface_data->prototype, prototype_functions);
- DCHECK(success);
-
- JS::RootedObject function_prototype(
- context, JS_GetFunctionPrototype(context, global_object));
- DCHECK(function_prototype);
- // Create the Interface object.
- interface_data->interface_object = JS_NewObjectWithGivenProto(
- context, &interface_data->interface_object_class_definition,
- function_prototype, NULL);
-
- // Add the InterfaceObject.name property.
- JS::RootedObject rooted_interface_object(
- context, interface_data->interface_object);
- JS::RootedValue name_value(context);
- const char name[] =
- "EnumerationInterface";
- name_value.setString(JS_NewStringCopyZ(context, name));
- success =
- JS_DefineProperty(context, rooted_interface_object, "name", name_value,
- JS_PropertyStub, JS_StrictPropertyStub,
- JSPROP_READONLY);
- DCHECK(success);
-
- // Add the InterfaceObject.length property. It is set to the length of the
- // shortest argument list of all overload constructors.
- JS::RootedValue length_value(context);
- length_value.setInt32(0);
- success =
- JS_DefineProperty(context, rooted_interface_object, "length",
- length_value, JS_PropertyStub, JS_StrictPropertyStub,
- JSPROP_READONLY);
- DCHECK(success);
-
- // Define interface object properties (including constants).
- success = JS_DefineProperties(context, rooted_interface_object,
- interface_object_properties);
- DCHECK(success);
- // Define interface object functions (static).
- success = JS_DefineFunctions(context, rooted_interface_object,
- interface_object_functions);
- DCHECK(success);
-
-
- // Set the Prototype.constructor and Constructor.prototype properties.
- DCHECK(interface_data->interface_object);
- DCHECK(interface_data->prototype);
- JS::RootedObject rooted_prototype(context, interface_data->prototype);
- success = JS_LinkConstructorAndPrototype(
- context,
- rooted_interface_object,
- rooted_prototype);
- DCHECK(success);
-}
-
-InterfaceData* GetInterfaceData(JSContext* context) {
- MozjsGlobalEnvironment* global_environment =
- static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context));
- // Use the address of the properties definition for this interface as a
- // unique key for looking up the InterfaceData for this interface.
- intptr_t key = reinterpret_cast<intptr_t>(&own_properties);
- InterfaceData* interface_data = global_environment->GetInterfaceData(key);
- if (!interface_data) {
- interface_data = CreateCachedInterfaceData();
- DCHECK(interface_data);
- global_environment->CacheInterfaceData(key, interface_data);
- DCHECK_EQ(interface_data, global_environment->GetInterfaceData(key));
- }
- return interface_data;
-}
-
-} // namespace
-
-// static
-JSObject* MozjsEnumerationInterface::CreateProxy(
- JSContext* context, const scoped_refptr<Wrappable>& wrappable) {
- DCHECK(MozjsGlobalEnvironment::GetFromContext(context));
- JS::RootedObject global_object(
- context,
- MozjsGlobalEnvironment::GetFromContext(context)->global_object());
- DCHECK(global_object);
-
- InterfaceData* interface_data = GetInterfaceData(context);
- JS::RootedObject prototype(context, GetPrototype(context, global_object));
- DCHECK(prototype);
- JS::RootedObject new_object(context, JS_NewObjectWithGivenProto(
- context, &interface_data->instance_class_definition, prototype, NULL));
- DCHECK(new_object);
- JS::RootedObject proxy(context,
- ProxyHandler::NewProxy(context, new_object, prototype, NULL,
- proxy_handler.Pointer()));
- WrapperPrivate::AddPrivateData(context, proxy, wrappable);
- return proxy;
-}
-
-//static
-const JSClass* MozjsEnumerationInterface::PrototypeClass(
- JSContext* context) {
- DCHECK(MozjsGlobalEnvironment::GetFromContext(context));
- JS::RootedObject global_object(
- context,
- MozjsGlobalEnvironment::GetFromContext(context)->global_object());
- DCHECK(global_object);
-
- JS::RootedObject prototype(context, GetPrototype(context, global_object));
- JSClass* proto_class = JS_GetClass(*prototype.address());
- return proto_class;
-}
-
-// static
-JSObject* MozjsEnumerationInterface::GetPrototype(
- JSContext* context, JS::HandleObject global_object) {
- DCHECK(JS_IsGlobalObject(global_object));
-
- InterfaceData* interface_data = GetInterfaceData(context);
- if (!interface_data->prototype) {
- // Create new prototype that has all the props and methods
- InitializePrototypeAndInterfaceObject(
- interface_data, context, global_object);
- }
- DCHECK(interface_data->prototype);
- return interface_data->prototype;
-}
-
-// static
-JSObject* MozjsEnumerationInterface::GetInterfaceObject(
- JSContext* context, JS::HandleObject global_object) {
- DCHECK(JS_IsGlobalObject(global_object));
-
- InterfaceData* interface_data = GetInterfaceData(context);
- if (!interface_data->interface_object) {
- InitializePrototypeAndInterfaceObject(
- interface_data, context, global_object);
- }
- DCHECK(interface_data->interface_object);
- return interface_data->interface_object;
-}
-
-
-namespace {
-JSBool Constructor(JSContext* context, unsigned int argc, JS::Value* vp) {
- MozjsExceptionState exception_state(context);
- JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
-
- scoped_refptr<EnumerationInterface> new_object =
- new EnumerationInterface();
- JS::RootedValue result_value(context);
- ToJSValue(context, new_object, &result_value);
- DCHECK(result_value.isObject());
- JS::RootedObject result_object(context, JSVAL_TO_OBJECT(result_value));
- args.rval().setObject(*result_object);
- return true;
-}
-} // namespace
-
-
-} // namespace testing
-} // namespace bindings
-} // namespace cobalt
diff --git a/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_enumeration_interface.h b/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_enumeration_interface.h
deleted file mode 100644
index b30fe69..0000000
--- a/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_enumeration_interface.h
+++ /dev/null
@@ -1,52 +0,0 @@
-// Copyright 2017 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/mozjs/templates/interface.h.template
-
-#ifndef MozjsEnumerationInterface_h
-#define MozjsEnumerationInterface_h
-
-#include "base/hash_tables.h"
-#include "base/lazy_instance.h"
-#include "base/memory/ref_counted.h"
-#include "base/threading/thread_checker.h"
-#include "cobalt/base/polymorphic_downcast.h"
-#include "cobalt/script/wrappable.h"
-#include "cobalt/bindings/testing/enumeration_interface.h"
-
-#include "third_party/mozjs/js/src/jsapi.h"
-
-namespace cobalt {
-namespace bindings {
-namespace testing {
-
-class MozjsEnumerationInterface {
- public:
- static JSObject* CreateProxy(JSContext* context,
- const scoped_refptr<script::Wrappable>& wrappable);
- static const JSClass* PrototypeClass(JSContext* context);
- static JSObject* GetPrototype(JSContext* context,
- JS::HandleObject global_object);
- static JSObject* GetInterfaceObject(JSContext* context,
- JS::HandleObject global_object);
-};
-
-} // namespace testing
-} // namespace bindings
-} // namespace cobalt
-
-#endif // MozjsEnumerationInterface_h
diff --git a/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_exception_object_interface.cc b/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_exception_object_interface.cc
deleted file mode 100644
index 9b4ff43..0000000
--- a/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_exception_object_interface.cc
+++ /dev/null
@@ -1,467 +0,0 @@
-// Copyright 2017 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/mozjs/templates/interface.cc.template
-
-#include "cobalt/bindings/testing/mozjs_exception_object_interface.h"
-
-#include "base/debug/trace_event.h"
-#include "cobalt/base/polymorphic_downcast.h"
-#include "cobalt/script/global_environment.h"
-#include "cobalt/script/opaque_handle.h"
-#include "cobalt/script/script_value.h"
-
-#include "mozjs_gen_type_conversion.h"
-
-#include "base/lazy_instance.h"
-#include "cobalt/script/exception_state.h"
-#include "cobalt/script/mozjs/callback_function_conversion.h"
-#include "cobalt/script/mozjs/conversion_helpers.h"
-#include "cobalt/script/mozjs/mozjs_callback_function.h"
-#include "cobalt/script/mozjs/mozjs_exception_state.h"
-#include "cobalt/script/mozjs/mozjs_global_environment.h"
-#include "cobalt/script/mozjs/mozjs_object_handle.h"
-#include "cobalt/script/mozjs/mozjs_property_enumerator.h"
-#include "cobalt/script/mozjs/mozjs_user_object_holder.h"
-#include "cobalt/script/mozjs/mozjs_value_handle.h"
-#include "cobalt/script/mozjs/native_promise.h"
-#include "cobalt/script/mozjs/proxy_handler.h"
-#include "cobalt/script/mozjs/type_traits.h"
-#include "cobalt/script/mozjs/wrapper_factory.h"
-#include "cobalt/script/mozjs/wrapper_private.h"
-#include "cobalt/script/property_enumerator.h"
-#include "cobalt/script/sequence.h"
-#include "third_party/mozjs/js/src/jsapi.h"
-#include "third_party/mozjs/js/src/jsexn.h"
-#include "third_party/mozjs/js/src/jsfriendapi.h"
-
-namespace {
-using cobalt::bindings::testing::ExceptionObjectInterface;
-using cobalt::bindings::testing::MozjsExceptionObjectInterface;
-using cobalt::script::CallbackInterfaceTraits;
-using cobalt::script::GlobalEnvironment;
-using cobalt::script::OpaqueHandle;
-using cobalt::script::OpaqueHandleHolder;
-using cobalt::script::ScriptValue;
-using cobalt::script::ValueHandle;
-using cobalt::script::Wrappable;
-
-using cobalt::script::CallbackFunction;
-using cobalt::script::CallbackInterfaceTraits;
-using cobalt::script::ExceptionState;
-using cobalt::script::Wrappable;
-using cobalt::script::mozjs::FromJSValue;
-using cobalt::script::mozjs::InterfaceData;
-using cobalt::script::mozjs::MozjsCallbackFunction;
-using cobalt::script::mozjs::MozjsExceptionState;
-using cobalt::script::mozjs::MozjsGlobalEnvironment;
-using cobalt::script::mozjs::MozjsPropertyEnumerator;
-using cobalt::script::mozjs::MozjsUserObjectHolder;
-using cobalt::script::mozjs::ProxyHandler;
-using cobalt::script::mozjs::ToJSValue;
-using cobalt::script::mozjs::TypeTraits;
-using cobalt::script::mozjs::WrapperFactory;
-using cobalt::script::mozjs::WrapperPrivate;
-using cobalt::script::mozjs::kConversionFlagClamped;
-using cobalt::script::mozjs::kConversionFlagNullable;
-using cobalt::script::mozjs::kConversionFlagRestricted;
-using cobalt::script::mozjs::kConversionFlagTreatNullAsEmptyString;
-using cobalt::script::mozjs::kConversionFlagTreatUndefinedAsEmptyString;
-using cobalt::script::mozjs::kNoConversionFlags;
-} // namespace
-
-namespace cobalt {
-namespace bindings {
-namespace testing {
-
-namespace {
-
-class MozjsExceptionObjectInterfaceHandler : public ProxyHandler {
- public:
- MozjsExceptionObjectInterfaceHandler()
- : ProxyHandler(indexed_property_hooks, named_property_hooks) {}
-
- private:
- static NamedPropertyHooks named_property_hooks;
- static IndexedPropertyHooks indexed_property_hooks;
-};
-
-ProxyHandler::NamedPropertyHooks
-MozjsExceptionObjectInterfaceHandler::named_property_hooks = {
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
-};
-ProxyHandler::IndexedPropertyHooks
-MozjsExceptionObjectInterfaceHandler::indexed_property_hooks = {
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
-};
-
-static base::LazyInstance<MozjsExceptionObjectInterfaceHandler>
- proxy_handler;
-
-JSBool HasInstance(JSContext *context, JS::HandleObject type,
- JS::MutableHandleValue vp, JSBool *success) {
- JS::RootedObject global_object(
- context, JS_GetGlobalForObject(context, type));
- DCHECK(global_object);
-
- JS::RootedObject prototype(
- context, MozjsExceptionObjectInterface::GetPrototype(context, global_object));
-
- // |IsDelegate| walks the prototype chain of an object returning true if
- // .prototype is found.
- bool is_delegate;
- if (!IsDelegate(context, prototype, vp, &is_delegate)) {
- *success = false;
- return false;
- }
-
- *success = is_delegate;
- return true;
-}
-
-InterfaceData* CreateCachedInterfaceData() {
- InterfaceData* interface_data = new InterfaceData();
- memset(&interface_data->instance_class_definition, 0,
- sizeof(interface_data->instance_class_definition));
- memset(&interface_data->prototype_class_definition, 0,
- sizeof(interface_data->prototype_class_definition));
- memset(&interface_data->interface_object_class_definition, 0,
- sizeof(interface_data->interface_object_class_definition));
-
- JSClass* instance_class = &interface_data->instance_class_definition;
- const int kGlobalFlags = 0;
- instance_class->name = "ExceptionObjectInterface";
- instance_class->flags = kGlobalFlags | JSCLASS_HAS_PRIVATE;
- instance_class->addProperty = JS_PropertyStub;
- instance_class->delProperty = JS_DeletePropertyStub;
- instance_class->getProperty = JS_PropertyStub;
- instance_class->setProperty = JS_StrictPropertyStub;
- instance_class->enumerate = JS_EnumerateStub;
- instance_class->resolve = JS_ResolveStub;
- instance_class->convert = JS_ConvertStub;
- // Function to be called before on object of this class is garbage collected.
- instance_class->finalize = &WrapperPrivate::Finalizer;
- // Called to trace objects that can be referenced from this object.
- instance_class->trace = &WrapperPrivate::Trace;
-
- JSClass* prototype_class = &interface_data->prototype_class_definition;
- prototype_class->name = "ExceptionObjectInterfacePrototype";
- prototype_class->flags = 0;
- prototype_class->addProperty = JS_PropertyStub;
- prototype_class->delProperty = JS_DeletePropertyStub;
- prototype_class->getProperty = JS_PropertyStub;
- prototype_class->setProperty = JS_StrictPropertyStub;
- prototype_class->enumerate = JS_EnumerateStub;
- prototype_class->resolve = JS_ResolveStub;
- prototype_class->convert = JS_ConvertStub;
-
- JSClass* interface_object_class =
- &interface_data->interface_object_class_definition;
- interface_object_class->name = "ExceptionObjectInterfaceConstructor";
- interface_object_class->flags = 0;
- interface_object_class->addProperty = JS_PropertyStub;
- interface_object_class->delProperty = JS_DeletePropertyStub;
- interface_object_class->getProperty = JS_PropertyStub;
- interface_object_class->setProperty = JS_StrictPropertyStub;
- interface_object_class->enumerate = JS_EnumerateStub;
- interface_object_class->resolve = JS_ResolveStub;
- interface_object_class->convert = JS_ConvertStub;
- interface_object_class->hasInstance = &HasInstance;
- return interface_data;
-}
-
-JSBool get_error(
- JSContext* context, JS::HandleObject object, JS::HandleId id,
- JS::MutableHandleValue vp) {
- const JSClass* proto_class =
- MozjsExceptionObjectInterface::PrototypeClass(context);
- if (proto_class == JS_GetClass(object)) {
- // Simply returns true if the object is this class's prototype object.
- // There is no need to return any value due to the object is not a platform
- // object. The execution reaches here when Object.getOwnPropertyDescriptor
- // gets called on native object prototypes.
- return true;
- }
-
- MozjsGlobalEnvironment* global_environment =
- static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context));
- WrapperFactory* wrapper_factory = global_environment->wrapper_factory();
- if (!wrapper_factory->DoesObjectImplementInterface(
- object, base::GetTypeId<ExceptionObjectInterface>())) {
- MozjsExceptionState exception(context);
- exception.SetSimpleException(script::kDoesNotImplementInterface);
- return false;
- }
- MozjsExceptionState exception_state(context);
- JS::RootedValue result_value(context);
-
- WrapperPrivate* wrapper_private =
- WrapperPrivate::GetFromObject(context, object);
- ExceptionObjectInterface* impl =
- wrapper_private->wrappable<ExceptionObjectInterface>().get();
-
- if (!exception_state.is_exception_set()) {
- ToJSValue(context,
- impl->error(),
- &result_value);
- }
- if (!exception_state.is_exception_set()) {
- vp.set(result_value);
- }
- return !exception_state.is_exception_set();
-}
-
-JSBool get_message(
- JSContext* context, JS::HandleObject object, JS::HandleId id,
- JS::MutableHandleValue vp) {
- const JSClass* proto_class =
- MozjsExceptionObjectInterface::PrototypeClass(context);
- if (proto_class == JS_GetClass(object)) {
- // Simply returns true if the object is this class's prototype object.
- // There is no need to return any value due to the object is not a platform
- // object. The execution reaches here when Object.getOwnPropertyDescriptor
- // gets called on native object prototypes.
- return true;
- }
-
- MozjsGlobalEnvironment* global_environment =
- static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context));
- WrapperFactory* wrapper_factory = global_environment->wrapper_factory();
- if (!wrapper_factory->DoesObjectImplementInterface(
- object, base::GetTypeId<ExceptionObjectInterface>())) {
- MozjsExceptionState exception(context);
- exception.SetSimpleException(script::kDoesNotImplementInterface);
- return false;
- }
- MozjsExceptionState exception_state(context);
- JS::RootedValue result_value(context);
-
- WrapperPrivate* wrapper_private =
- WrapperPrivate::GetFromObject(context, object);
- ExceptionObjectInterface* impl =
- wrapper_private->wrappable<ExceptionObjectInterface>().get();
-
- if (!exception_state.is_exception_set()) {
- ToJSValue(context,
- impl->message(),
- &result_value);
- }
- if (!exception_state.is_exception_set()) {
- vp.set(result_value);
- }
- return !exception_state.is_exception_set();
-}
-
-
-const JSPropertySpec prototype_properties[] = {
- { // Readonly attribute
- "error", 0,
- JSPROP_SHARED | JSPROP_ENUMERATE | JSPROP_READONLY,
- JSOP_WRAPPER(&get_error),
- JSOP_NULLWRAPPER,
- },
- { // Readonly attribute
- "message", 0,
- JSPROP_SHARED | JSPROP_ENUMERATE | JSPROP_READONLY,
- JSOP_WRAPPER(&get_message),
- JSOP_NULLWRAPPER,
- },
- JS_PS_END
-};
-
-const JSFunctionSpec prototype_functions[] = {
- JS_FS_END
-};
-
-const JSPropertySpec interface_object_properties[] = {
- JS_PS_END
-};
-
-const JSFunctionSpec interface_object_functions[] = {
- JS_FS_END
-};
-
-const JSPropertySpec own_properties[] = {
- JS_PS_END
-};
-
-void InitializePrototypeAndInterfaceObject(
- InterfaceData* interface_data, JSContext* context,
- JS::HandleObject global_object) {
- DCHECK(!interface_data->prototype);
- DCHECK(!interface_data->interface_object);
- DCHECK(JS_IsGlobalObject(global_object));
-
- // Get Error prototype.
- JS::RootedObject parent_prototype(context);
- bool success_check = js_GetClassPrototype(
- context, GetExceptionProtoKey(JSEXN_ERR), &parent_prototype);
- DCHECK(success_check);
- DCHECK(parent_prototype);
-
- // Create the Prototype object.
- interface_data->prototype = JS_NewObjectWithGivenProto(
- context, &interface_data->prototype_class_definition, parent_prototype,
- NULL);
- bool success = JS_DefineProperties(
- context, interface_data->prototype, prototype_properties);
- DCHECK(success);
- success = JS_DefineFunctions(
- context, interface_data->prototype, prototype_functions);
- DCHECK(success);
-
- JS::RootedObject function_prototype(
- context, JS_GetFunctionPrototype(context, global_object));
- DCHECK(function_prototype);
- // Create the Interface object.
- interface_data->interface_object = JS_NewObjectWithGivenProto(
- context, &interface_data->interface_object_class_definition,
- function_prototype, NULL);
-
- // Add the InterfaceObject.name property.
- JS::RootedObject rooted_interface_object(
- context, interface_data->interface_object);
- JS::RootedValue name_value(context);
- const char name[] =
- "ExceptionObjectInterface";
- name_value.setString(JS_NewStringCopyZ(context, name));
- success =
- JS_DefineProperty(context, rooted_interface_object, "name", name_value,
- JS_PropertyStub, JS_StrictPropertyStub,
- JSPROP_READONLY);
- DCHECK(success);
-
- // Define interface object properties (including constants).
- success = JS_DefineProperties(context, rooted_interface_object,
- interface_object_properties);
- DCHECK(success);
- // Define interface object functions (static).
- success = JS_DefineFunctions(context, rooted_interface_object,
- interface_object_functions);
- DCHECK(success);
-
-
- // Set the Prototype.constructor and Constructor.prototype properties.
- DCHECK(interface_data->interface_object);
- DCHECK(interface_data->prototype);
- JS::RootedObject rooted_prototype(context, interface_data->prototype);
- success = JS_LinkConstructorAndPrototype(
- context,
- rooted_interface_object,
- rooted_prototype);
- DCHECK(success);
-}
-
-InterfaceData* GetInterfaceData(JSContext* context) {
- MozjsGlobalEnvironment* global_environment =
- static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context));
- // Use the address of the properties definition for this interface as a
- // unique key for looking up the InterfaceData for this interface.
- intptr_t key = reinterpret_cast<intptr_t>(&own_properties);
- InterfaceData* interface_data = global_environment->GetInterfaceData(key);
- if (!interface_data) {
- interface_data = CreateCachedInterfaceData();
- DCHECK(interface_data);
- global_environment->CacheInterfaceData(key, interface_data);
- DCHECK_EQ(interface_data, global_environment->GetInterfaceData(key));
- }
- return interface_data;
-}
-
-} // namespace
-
-// static
-JSObject* MozjsExceptionObjectInterface::CreateProxy(
- JSContext* context, const scoped_refptr<Wrappable>& wrappable) {
- DCHECK(MozjsGlobalEnvironment::GetFromContext(context));
- JS::RootedObject global_object(
- context,
- MozjsGlobalEnvironment::GetFromContext(context)->global_object());
- DCHECK(global_object);
-
- InterfaceData* interface_data = GetInterfaceData(context);
- JS::RootedObject prototype(context, GetPrototype(context, global_object));
- DCHECK(prototype);
- JS::RootedObject new_object(context, JS_NewObjectWithGivenProto(
- context, &interface_data->instance_class_definition, prototype, NULL));
- DCHECK(new_object);
- JS::RootedObject proxy(context,
- ProxyHandler::NewProxy(context, new_object, prototype, NULL,
- proxy_handler.Pointer()));
- WrapperPrivate::AddPrivateData(context, proxy, wrappable);
- return proxy;
-}
-
-//static
-const JSClass* MozjsExceptionObjectInterface::PrototypeClass(
- JSContext* context) {
- DCHECK(MozjsGlobalEnvironment::GetFromContext(context));
- JS::RootedObject global_object(
- context,
- MozjsGlobalEnvironment::GetFromContext(context)->global_object());
- DCHECK(global_object);
-
- JS::RootedObject prototype(context, GetPrototype(context, global_object));
- JSClass* proto_class = JS_GetClass(*prototype.address());
- return proto_class;
-}
-
-// static
-JSObject* MozjsExceptionObjectInterface::GetPrototype(
- JSContext* context, JS::HandleObject global_object) {
- DCHECK(JS_IsGlobalObject(global_object));
-
- InterfaceData* interface_data = GetInterfaceData(context);
- if (!interface_data->prototype) {
- // Create new prototype that has all the props and methods
- InitializePrototypeAndInterfaceObject(
- interface_data, context, global_object);
- }
- DCHECK(interface_data->prototype);
- return interface_data->prototype;
-}
-
-// static
-JSObject* MozjsExceptionObjectInterface::GetInterfaceObject(
- JSContext* context, JS::HandleObject global_object) {
- DCHECK(JS_IsGlobalObject(global_object));
-
- InterfaceData* interface_data = GetInterfaceData(context);
- if (!interface_data->interface_object) {
- InitializePrototypeAndInterfaceObject(
- interface_data, context, global_object);
- }
- DCHECK(interface_data->interface_object);
- return interface_data->interface_object;
-}
-
-
-namespace {
-} // namespace
-
-
-} // namespace testing
-} // namespace bindings
-} // namespace cobalt
diff --git a/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_exception_object_interface.h b/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_exception_object_interface.h
deleted file mode 100644
index 9f38fbe..0000000
--- a/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_exception_object_interface.h
+++ /dev/null
@@ -1,52 +0,0 @@
-// Copyright 2017 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/mozjs/templates/interface.h.template
-
-#ifndef MozjsExceptionObjectInterface_h
-#define MozjsExceptionObjectInterface_h
-
-#include "base/hash_tables.h"
-#include "base/lazy_instance.h"
-#include "base/memory/ref_counted.h"
-#include "base/threading/thread_checker.h"
-#include "cobalt/base/polymorphic_downcast.h"
-#include "cobalt/script/wrappable.h"
-#include "cobalt/bindings/testing/exception_object_interface.h"
-
-#include "third_party/mozjs/js/src/jsapi.h"
-
-namespace cobalt {
-namespace bindings {
-namespace testing {
-
-class MozjsExceptionObjectInterface {
- public:
- static JSObject* CreateProxy(JSContext* context,
- const scoped_refptr<script::Wrappable>& wrappable);
- static const JSClass* PrototypeClass(JSContext* context);
- static JSObject* GetPrototype(JSContext* context,
- JS::HandleObject global_object);
- static JSObject* GetInterfaceObject(JSContext* context,
- JS::HandleObject global_object);
-};
-
-} // namespace testing
-} // namespace bindings
-} // namespace cobalt
-
-#endif // MozjsExceptionObjectInterface_h
diff --git a/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_exceptions_interface.cc b/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_exceptions_interface.cc
deleted file mode 100644
index f4b2722..0000000
--- a/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_exceptions_interface.cc
+++ /dev/null
@@ -1,539 +0,0 @@
-// Copyright 2017 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/mozjs/templates/interface.cc.template
-
-#include "cobalt/bindings/testing/mozjs_exceptions_interface.h"
-
-#include "base/debug/trace_event.h"
-#include "cobalt/base/polymorphic_downcast.h"
-#include "cobalt/script/global_environment.h"
-#include "cobalt/script/opaque_handle.h"
-#include "cobalt/script/script_value.h"
-
-#include "mozjs_gen_type_conversion.h"
-
-#include "base/lazy_instance.h"
-#include "cobalt/script/exception_state.h"
-#include "cobalt/script/mozjs/callback_function_conversion.h"
-#include "cobalt/script/mozjs/conversion_helpers.h"
-#include "cobalt/script/mozjs/mozjs_callback_function.h"
-#include "cobalt/script/mozjs/mozjs_exception_state.h"
-#include "cobalt/script/mozjs/mozjs_global_environment.h"
-#include "cobalt/script/mozjs/mozjs_object_handle.h"
-#include "cobalt/script/mozjs/mozjs_property_enumerator.h"
-#include "cobalt/script/mozjs/mozjs_user_object_holder.h"
-#include "cobalt/script/mozjs/mozjs_value_handle.h"
-#include "cobalt/script/mozjs/native_promise.h"
-#include "cobalt/script/mozjs/proxy_handler.h"
-#include "cobalt/script/mozjs/type_traits.h"
-#include "cobalt/script/mozjs/wrapper_factory.h"
-#include "cobalt/script/mozjs/wrapper_private.h"
-#include "cobalt/script/property_enumerator.h"
-#include "cobalt/script/sequence.h"
-#include "third_party/mozjs/js/src/jsapi.h"
-#include "third_party/mozjs/js/src/jsfriendapi.h"
-
-namespace {
-using cobalt::bindings::testing::ExceptionsInterface;
-using cobalt::bindings::testing::MozjsExceptionsInterface;
-using cobalt::script::CallbackInterfaceTraits;
-using cobalt::script::GlobalEnvironment;
-using cobalt::script::OpaqueHandle;
-using cobalt::script::OpaqueHandleHolder;
-using cobalt::script::ScriptValue;
-using cobalt::script::ValueHandle;
-using cobalt::script::Wrappable;
-
-using cobalt::script::CallbackFunction;
-using cobalt::script::CallbackInterfaceTraits;
-using cobalt::script::ExceptionState;
-using cobalt::script::Wrappable;
-using cobalt::script::mozjs::FromJSValue;
-using cobalt::script::mozjs::InterfaceData;
-using cobalt::script::mozjs::MozjsCallbackFunction;
-using cobalt::script::mozjs::MozjsExceptionState;
-using cobalt::script::mozjs::MozjsGlobalEnvironment;
-using cobalt::script::mozjs::MozjsPropertyEnumerator;
-using cobalt::script::mozjs::MozjsUserObjectHolder;
-using cobalt::script::mozjs::ProxyHandler;
-using cobalt::script::mozjs::ToJSValue;
-using cobalt::script::mozjs::TypeTraits;
-using cobalt::script::mozjs::WrapperFactory;
-using cobalt::script::mozjs::WrapperPrivate;
-using cobalt::script::mozjs::kConversionFlagClamped;
-using cobalt::script::mozjs::kConversionFlagNullable;
-using cobalt::script::mozjs::kConversionFlagRestricted;
-using cobalt::script::mozjs::kConversionFlagTreatNullAsEmptyString;
-using cobalt::script::mozjs::kConversionFlagTreatUndefinedAsEmptyString;
-using cobalt::script::mozjs::kNoConversionFlags;
-} // namespace
-
-namespace cobalt {
-namespace bindings {
-namespace testing {
-
-namespace {
-
-class MozjsExceptionsInterfaceHandler : public ProxyHandler {
- public:
- MozjsExceptionsInterfaceHandler()
- : ProxyHandler(indexed_property_hooks, named_property_hooks) {}
-
- private:
- static NamedPropertyHooks named_property_hooks;
- static IndexedPropertyHooks indexed_property_hooks;
-};
-
-ProxyHandler::NamedPropertyHooks
-MozjsExceptionsInterfaceHandler::named_property_hooks = {
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
-};
-ProxyHandler::IndexedPropertyHooks
-MozjsExceptionsInterfaceHandler::indexed_property_hooks = {
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
-};
-
-static base::LazyInstance<MozjsExceptionsInterfaceHandler>
- proxy_handler;
-
-JSBool Constructor(JSContext* context, unsigned int argc, JS::Value* vp);
-JSBool HasInstance(JSContext *context, JS::HandleObject type,
- JS::MutableHandleValue vp, JSBool *success) {
- JS::RootedObject global_object(
- context, JS_GetGlobalForObject(context, type));
- DCHECK(global_object);
-
- JS::RootedObject prototype(
- context, MozjsExceptionsInterface::GetPrototype(context, global_object));
-
- // |IsDelegate| walks the prototype chain of an object returning true if
- // .prototype is found.
- bool is_delegate;
- if (!IsDelegate(context, prototype, vp, &is_delegate)) {
- *success = false;
- return false;
- }
-
- *success = is_delegate;
- return true;
-}
-
-InterfaceData* CreateCachedInterfaceData() {
- InterfaceData* interface_data = new InterfaceData();
- memset(&interface_data->instance_class_definition, 0,
- sizeof(interface_data->instance_class_definition));
- memset(&interface_data->prototype_class_definition, 0,
- sizeof(interface_data->prototype_class_definition));
- memset(&interface_data->interface_object_class_definition, 0,
- sizeof(interface_data->interface_object_class_definition));
-
- JSClass* instance_class = &interface_data->instance_class_definition;
- const int kGlobalFlags = 0;
- instance_class->name = "ExceptionsInterface";
- instance_class->flags = kGlobalFlags | JSCLASS_HAS_PRIVATE;
- instance_class->addProperty = JS_PropertyStub;
- instance_class->delProperty = JS_DeletePropertyStub;
- instance_class->getProperty = JS_PropertyStub;
- instance_class->setProperty = JS_StrictPropertyStub;
- instance_class->enumerate = JS_EnumerateStub;
- instance_class->resolve = JS_ResolveStub;
- instance_class->convert = JS_ConvertStub;
- // Function to be called before on object of this class is garbage collected.
- instance_class->finalize = &WrapperPrivate::Finalizer;
- // Called to trace objects that can be referenced from this object.
- instance_class->trace = &WrapperPrivate::Trace;
-
- JSClass* prototype_class = &interface_data->prototype_class_definition;
- prototype_class->name = "ExceptionsInterfacePrototype";
- prototype_class->flags = 0;
- prototype_class->addProperty = JS_PropertyStub;
- prototype_class->delProperty = JS_DeletePropertyStub;
- prototype_class->getProperty = JS_PropertyStub;
- prototype_class->setProperty = JS_StrictPropertyStub;
- prototype_class->enumerate = JS_EnumerateStub;
- prototype_class->resolve = JS_ResolveStub;
- prototype_class->convert = JS_ConvertStub;
-
- JSClass* interface_object_class =
- &interface_data->interface_object_class_definition;
- interface_object_class->name = "ExceptionsInterfaceConstructor";
- interface_object_class->flags = 0;
- interface_object_class->addProperty = JS_PropertyStub;
- interface_object_class->delProperty = JS_DeletePropertyStub;
- interface_object_class->getProperty = JS_PropertyStub;
- interface_object_class->setProperty = JS_StrictPropertyStub;
- interface_object_class->enumerate = JS_EnumerateStub;
- interface_object_class->resolve = JS_ResolveStub;
- interface_object_class->convert = JS_ConvertStub;
- interface_object_class->hasInstance = &HasInstance;
- interface_object_class->construct = Constructor;
- return interface_data;
-}
-
-JSBool get_attributeThrowsException(
- JSContext* context, JS::HandleObject object, JS::HandleId id,
- JS::MutableHandleValue vp) {
- const JSClass* proto_class =
- MozjsExceptionsInterface::PrototypeClass(context);
- if (proto_class == JS_GetClass(object)) {
- // Simply returns true if the object is this class's prototype object.
- // There is no need to return any value due to the object is not a platform
- // object. The execution reaches here when Object.getOwnPropertyDescriptor
- // gets called on native object prototypes.
- return true;
- }
-
- MozjsGlobalEnvironment* global_environment =
- static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context));
- WrapperFactory* wrapper_factory = global_environment->wrapper_factory();
- if (!wrapper_factory->DoesObjectImplementInterface(
- object, base::GetTypeId<ExceptionsInterface>())) {
- MozjsExceptionState exception(context);
- exception.SetSimpleException(script::kDoesNotImplementInterface);
- return false;
- }
- MozjsExceptionState exception_state(context);
- JS::RootedValue result_value(context);
-
- WrapperPrivate* wrapper_private =
- WrapperPrivate::GetFromObject(context, object);
- ExceptionsInterface* impl =
- wrapper_private->wrappable<ExceptionsInterface>().get();
-
- if (!exception_state.is_exception_set()) {
- ToJSValue(context,
- impl->attribute_throws_exception(&exception_state),
- &result_value);
- }
- if (!exception_state.is_exception_set()) {
- vp.set(result_value);
- }
- return !exception_state.is_exception_set();
-}
-
-JSBool set_attributeThrowsException(
- JSContext* context, JS::HandleObject object, JS::HandleId id,
- JSBool strict, JS::MutableHandleValue vp) {
- const JSClass* proto_class =
- MozjsExceptionsInterface::PrototypeClass(context);
- if (proto_class == JS_GetClass(object)) {
- // Simply returns true if the object is this class's prototype object.
- // There is no need to return any value due to the object is not a platform
- // object. The execution reaches here when Object.getOwnPropertyDescriptor
- // gets called on native object prototypes.
- return true;
- }
-
- MozjsGlobalEnvironment* global_environment =
- static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context));
- WrapperFactory* wrapper_factory = global_environment->wrapper_factory();
- if (!wrapper_factory->DoesObjectImplementInterface(
- object, base::GetTypeId<ExceptionsInterface>())) {
- MozjsExceptionState exception(context);
- exception.SetSimpleException(script::kDoesNotImplementInterface);
- return false;
- }
- MozjsExceptionState exception_state(context);
- JS::RootedValue result_value(context);
-
- WrapperPrivate* wrapper_private =
- WrapperPrivate::GetFromObject(context, object);
- ExceptionsInterface* impl =
- wrapper_private->wrappable<ExceptionsInterface>().get();
- TypeTraits<bool >::ConversionType value;
- FromJSValue(context, vp, kNoConversionFlags, &exception_state,
- &value);
- if (exception_state.is_exception_set()) {
- return false;
- }
-
- impl->set_attribute_throws_exception(value, &exception_state);
- result_value.set(JS::UndefinedHandleValue);
- return !exception_state.is_exception_set();
-}
-
-JSBool fcn_functionThrowsException(
- JSContext* context, uint32_t argc, JS::Value *vp) {
- JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
- // Compute the 'this' value.
- JS::RootedValue this_value(context, JS_ComputeThis(context, vp));
- // 'this' should be an object.
- JS::RootedObject object(context);
- if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) {
- return false;
- }
- if (!JS_ValueToObject(context, this_value, object.address())) {
- NOTREACHED();
- return false;
- }
- const JSClass* proto_class =
- MozjsExceptionsInterface::PrototypeClass(context);
- if (proto_class == JS_GetClass(object)) {
- // Simply returns true if the object is this class's prototype object.
- // There is no need to return any value due to the object is not a platform
- // object. The execution reaches here when Object.getOwnPropertyDescriptor
- // gets called on native object prototypes.
- return true;
- }
-
- MozjsGlobalEnvironment* global_environment =
- static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context));
- WrapperFactory* wrapper_factory = global_environment->wrapper_factory();
- if (!wrapper_factory->DoesObjectImplementInterface(
- object, base::GetTypeId<ExceptionsInterface>())) {
- MozjsExceptionState exception(context);
- exception.SetSimpleException(script::kDoesNotImplementInterface);
- return false;
- }
- MozjsExceptionState exception_state(context);
- JS::RootedValue result_value(context);
-
- WrapperPrivate* wrapper_private =
- WrapperPrivate::GetFromObject(context, object);
- ExceptionsInterface* impl =
- wrapper_private->wrappable<ExceptionsInterface>().get();
-
- impl->FunctionThrowsException(&exception_state);
- result_value.set(JS::UndefinedHandleValue);
- return !exception_state.is_exception_set();
-}
-
-
-const JSPropertySpec prototype_properties[] = {
- { // Read/Write property
- "attributeThrowsException", 0,
- JSPROP_SHARED | JSPROP_ENUMERATE,
- JSOP_WRAPPER(&get_attributeThrowsException),
- JSOP_WRAPPER(&set_attributeThrowsException),
- },
- JS_PS_END
-};
-
-const JSFunctionSpec prototype_functions[] = {
- {
- "functionThrowsException",
- JSOP_WRAPPER(&fcn_functionThrowsException),
- 0,
- JSPROP_ENUMERATE,
- NULL,
- },
- JS_FS_END
-};
-
-const JSPropertySpec interface_object_properties[] = {
- JS_PS_END
-};
-
-const JSFunctionSpec interface_object_functions[] = {
- JS_FS_END
-};
-
-const JSPropertySpec own_properties[] = {
- JS_PS_END
-};
-
-void InitializePrototypeAndInterfaceObject(
- InterfaceData* interface_data, JSContext* context,
- JS::HandleObject global_object) {
- DCHECK(!interface_data->prototype);
- DCHECK(!interface_data->interface_object);
- DCHECK(JS_IsGlobalObject(global_object));
-
- JS::RootedObject parent_prototype(
- context, JS_GetObjectPrototype(context, global_object));
- DCHECK(parent_prototype);
-
- // Create the Prototype object.
- interface_data->prototype = JS_NewObjectWithGivenProto(
- context, &interface_data->prototype_class_definition, parent_prototype,
- NULL);
- bool success = JS_DefineProperties(
- context, interface_data->prototype, prototype_properties);
- DCHECK(success);
- success = JS_DefineFunctions(
- context, interface_data->prototype, prototype_functions);
- DCHECK(success);
-
- JS::RootedObject function_prototype(
- context, JS_GetFunctionPrototype(context, global_object));
- DCHECK(function_prototype);
- // Create the Interface object.
- interface_data->interface_object = JS_NewObjectWithGivenProto(
- context, &interface_data->interface_object_class_definition,
- function_prototype, NULL);
-
- // Add the InterfaceObject.name property.
- JS::RootedObject rooted_interface_object(
- context, interface_data->interface_object);
- JS::RootedValue name_value(context);
- const char name[] =
- "ExceptionsInterface";
- name_value.setString(JS_NewStringCopyZ(context, name));
- success =
- JS_DefineProperty(context, rooted_interface_object, "name", name_value,
- JS_PropertyStub, JS_StrictPropertyStub,
- JSPROP_READONLY);
- DCHECK(success);
-
- // Add the InterfaceObject.length property. It is set to the length of the
- // shortest argument list of all overload constructors.
- JS::RootedValue length_value(context);
- length_value.setInt32(0);
- success =
- JS_DefineProperty(context, rooted_interface_object, "length",
- length_value, JS_PropertyStub, JS_StrictPropertyStub,
- JSPROP_READONLY);
- DCHECK(success);
-
- // Define interface object properties (including constants).
- success = JS_DefineProperties(context, rooted_interface_object,
- interface_object_properties);
- DCHECK(success);
- // Define interface object functions (static).
- success = JS_DefineFunctions(context, rooted_interface_object,
- interface_object_functions);
- DCHECK(success);
-
-
- // Set the Prototype.constructor and Constructor.prototype properties.
- DCHECK(interface_data->interface_object);
- DCHECK(interface_data->prototype);
- JS::RootedObject rooted_prototype(context, interface_data->prototype);
- success = JS_LinkConstructorAndPrototype(
- context,
- rooted_interface_object,
- rooted_prototype);
- DCHECK(success);
-}
-
-InterfaceData* GetInterfaceData(JSContext* context) {
- MozjsGlobalEnvironment* global_environment =
- static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context));
- // Use the address of the properties definition for this interface as a
- // unique key for looking up the InterfaceData for this interface.
- intptr_t key = reinterpret_cast<intptr_t>(&own_properties);
- InterfaceData* interface_data = global_environment->GetInterfaceData(key);
- if (!interface_data) {
- interface_data = CreateCachedInterfaceData();
- DCHECK(interface_data);
- global_environment->CacheInterfaceData(key, interface_data);
- DCHECK_EQ(interface_data, global_environment->GetInterfaceData(key));
- }
- return interface_data;
-}
-
-} // namespace
-
-// static
-JSObject* MozjsExceptionsInterface::CreateProxy(
- JSContext* context, const scoped_refptr<Wrappable>& wrappable) {
- DCHECK(MozjsGlobalEnvironment::GetFromContext(context));
- JS::RootedObject global_object(
- context,
- MozjsGlobalEnvironment::GetFromContext(context)->global_object());
- DCHECK(global_object);
-
- InterfaceData* interface_data = GetInterfaceData(context);
- JS::RootedObject prototype(context, GetPrototype(context, global_object));
- DCHECK(prototype);
- JS::RootedObject new_object(context, JS_NewObjectWithGivenProto(
- context, &interface_data->instance_class_definition, prototype, NULL));
- DCHECK(new_object);
- JS::RootedObject proxy(context,
- ProxyHandler::NewProxy(context, new_object, prototype, NULL,
- proxy_handler.Pointer()));
- WrapperPrivate::AddPrivateData(context, proxy, wrappable);
- return proxy;
-}
-
-//static
-const JSClass* MozjsExceptionsInterface::PrototypeClass(
- JSContext* context) {
- DCHECK(MozjsGlobalEnvironment::GetFromContext(context));
- JS::RootedObject global_object(
- context,
- MozjsGlobalEnvironment::GetFromContext(context)->global_object());
- DCHECK(global_object);
-
- JS::RootedObject prototype(context, GetPrototype(context, global_object));
- JSClass* proto_class = JS_GetClass(*prototype.address());
- return proto_class;
-}
-
-// static
-JSObject* MozjsExceptionsInterface::GetPrototype(
- JSContext* context, JS::HandleObject global_object) {
- DCHECK(JS_IsGlobalObject(global_object));
-
- InterfaceData* interface_data = GetInterfaceData(context);
- if (!interface_data->prototype) {
- // Create new prototype that has all the props and methods
- InitializePrototypeAndInterfaceObject(
- interface_data, context, global_object);
- }
- DCHECK(interface_data->prototype);
- return interface_data->prototype;
-}
-
-// static
-JSObject* MozjsExceptionsInterface::GetInterfaceObject(
- JSContext* context, JS::HandleObject global_object) {
- DCHECK(JS_IsGlobalObject(global_object));
-
- InterfaceData* interface_data = GetInterfaceData(context);
- if (!interface_data->interface_object) {
- InitializePrototypeAndInterfaceObject(
- interface_data, context, global_object);
- }
- DCHECK(interface_data->interface_object);
- return interface_data->interface_object;
-}
-
-
-namespace {
-JSBool Constructor(JSContext* context, unsigned int argc, JS::Value* vp) {
- MozjsExceptionState exception_state(context);
- JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
-
- scoped_refptr<ExceptionsInterface> new_object =
- new ExceptionsInterface(&exception_state);
- // In case that an exception is thrown from constructor.
- if (exception_state.is_exception_set()) {
- return false;
- }
- JS::RootedValue result_value(context);
- ToJSValue(context, new_object, &result_value);
- DCHECK(result_value.isObject());
- JS::RootedObject result_object(context, JSVAL_TO_OBJECT(result_value));
- args.rval().setObject(*result_object);
- return true;
-}
-} // namespace
-
-
-} // namespace testing
-} // namespace bindings
-} // namespace cobalt
diff --git a/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_exceptions_interface.h b/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_exceptions_interface.h
deleted file mode 100644
index 49f9a24..0000000
--- a/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_exceptions_interface.h
+++ /dev/null
@@ -1,52 +0,0 @@
-// Copyright 2017 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/mozjs/templates/interface.h.template
-
-#ifndef MozjsExceptionsInterface_h
-#define MozjsExceptionsInterface_h
-
-#include "base/hash_tables.h"
-#include "base/lazy_instance.h"
-#include "base/memory/ref_counted.h"
-#include "base/threading/thread_checker.h"
-#include "cobalt/base/polymorphic_downcast.h"
-#include "cobalt/script/wrappable.h"
-#include "cobalt/bindings/testing/exceptions_interface.h"
-
-#include "third_party/mozjs/js/src/jsapi.h"
-
-namespace cobalt {
-namespace bindings {
-namespace testing {
-
-class MozjsExceptionsInterface {
- public:
- static JSObject* CreateProxy(JSContext* context,
- const scoped_refptr<script::Wrappable>& wrappable);
- static const JSClass* PrototypeClass(JSContext* context);
- static JSObject* GetPrototype(JSContext* context,
- JS::HandleObject global_object);
- static JSObject* GetInterfaceObject(JSContext* context,
- JS::HandleObject global_object);
-};
-
-} // namespace testing
-} // namespace bindings
-} // namespace cobalt
-
-#endif // MozjsExceptionsInterface_h
diff --git a/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_extended_idl_attributes_interface.cc b/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_extended_idl_attributes_interface.cc
deleted file mode 100644
index 1ff02f5..0000000
--- a/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_extended_idl_attributes_interface.cc
+++ /dev/null
@@ -1,583 +0,0 @@
-// Copyright 2017 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/mozjs/templates/interface.cc.template
-
-#include "cobalt/bindings/testing/mozjs_extended_idl_attributes_interface.h"
-
-#include "base/debug/trace_event.h"
-#include "cobalt/base/polymorphic_downcast.h"
-#include "cobalt/script/global_environment.h"
-#include "cobalt/script/opaque_handle.h"
-#include "cobalt/script/script_value.h"
-
-#include "mozjs_gen_type_conversion.h"
-
-#include "base/lazy_instance.h"
-#include "cobalt/script/exception_state.h"
-#include "cobalt/script/mozjs/callback_function_conversion.h"
-#include "cobalt/script/mozjs/conversion_helpers.h"
-#include "cobalt/script/mozjs/mozjs_callback_function.h"
-#include "cobalt/script/mozjs/mozjs_exception_state.h"
-#include "cobalt/script/mozjs/mozjs_global_environment.h"
-#include "cobalt/script/mozjs/mozjs_object_handle.h"
-#include "cobalt/script/mozjs/mozjs_property_enumerator.h"
-#include "cobalt/script/mozjs/mozjs_user_object_holder.h"
-#include "cobalt/script/mozjs/mozjs_value_handle.h"
-#include "cobalt/script/mozjs/native_promise.h"
-#include "cobalt/script/mozjs/proxy_handler.h"
-#include "cobalt/script/mozjs/type_traits.h"
-#include "cobalt/script/mozjs/wrapper_factory.h"
-#include "cobalt/script/mozjs/wrapper_private.h"
-#include "cobalt/script/property_enumerator.h"
-#include "cobalt/script/sequence.h"
-#include "third_party/mozjs/js/src/jsapi.h"
-#include "third_party/mozjs/js/src/jsfriendapi.h"
-
-namespace {
-using cobalt::bindings::testing::ExtendedIDLAttributesInterface;
-using cobalt::bindings::testing::MozjsExtendedIDLAttributesInterface;
-using cobalt::script::CallbackInterfaceTraits;
-using cobalt::script::GlobalEnvironment;
-using cobalt::script::OpaqueHandle;
-using cobalt::script::OpaqueHandleHolder;
-using cobalt::script::ScriptValue;
-using cobalt::script::ValueHandle;
-using cobalt::script::Wrappable;
-
-using cobalt::script::CallbackFunction;
-using cobalt::script::CallbackInterfaceTraits;
-using cobalt::script::ExceptionState;
-using cobalt::script::Wrappable;
-using cobalt::script::mozjs::FromJSValue;
-using cobalt::script::mozjs::InterfaceData;
-using cobalt::script::mozjs::MozjsCallbackFunction;
-using cobalt::script::mozjs::MozjsExceptionState;
-using cobalt::script::mozjs::MozjsGlobalEnvironment;
-using cobalt::script::mozjs::MozjsPropertyEnumerator;
-using cobalt::script::mozjs::MozjsUserObjectHolder;
-using cobalt::script::mozjs::ProxyHandler;
-using cobalt::script::mozjs::ToJSValue;
-using cobalt::script::mozjs::TypeTraits;
-using cobalt::script::mozjs::WrapperFactory;
-using cobalt::script::mozjs::WrapperPrivate;
-using cobalt::script::mozjs::kConversionFlagClamped;
-using cobalt::script::mozjs::kConversionFlagNullable;
-using cobalt::script::mozjs::kConversionFlagRestricted;
-using cobalt::script::mozjs::kConversionFlagTreatNullAsEmptyString;
-using cobalt::script::mozjs::kConversionFlagTreatUndefinedAsEmptyString;
-using cobalt::script::mozjs::kNoConversionFlags;
-} // namespace
-
-namespace cobalt {
-namespace bindings {
-namespace testing {
-
-namespace {
-
-class MozjsExtendedIDLAttributesInterfaceHandler : public ProxyHandler {
- public:
- MozjsExtendedIDLAttributesInterfaceHandler()
- : ProxyHandler(indexed_property_hooks, named_property_hooks) {}
-
- private:
- static NamedPropertyHooks named_property_hooks;
- static IndexedPropertyHooks indexed_property_hooks;
-};
-
-ProxyHandler::NamedPropertyHooks
-MozjsExtendedIDLAttributesInterfaceHandler::named_property_hooks = {
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
-};
-ProxyHandler::IndexedPropertyHooks
-MozjsExtendedIDLAttributesInterfaceHandler::indexed_property_hooks = {
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
-};
-
-static base::LazyInstance<MozjsExtendedIDLAttributesInterfaceHandler>
- proxy_handler;
-
-JSBool HasInstance(JSContext *context, JS::HandleObject type,
- JS::MutableHandleValue vp, JSBool *success) {
- JS::RootedObject global_object(
- context, JS_GetGlobalForObject(context, type));
- DCHECK(global_object);
-
- JS::RootedObject prototype(
- context, MozjsExtendedIDLAttributesInterface::GetPrototype(context, global_object));
-
- // |IsDelegate| walks the prototype chain of an object returning true if
- // .prototype is found.
- bool is_delegate;
- if (!IsDelegate(context, prototype, vp, &is_delegate)) {
- *success = false;
- return false;
- }
-
- *success = is_delegate;
- return true;
-}
-
-InterfaceData* CreateCachedInterfaceData() {
- InterfaceData* interface_data = new InterfaceData();
- memset(&interface_data->instance_class_definition, 0,
- sizeof(interface_data->instance_class_definition));
- memset(&interface_data->prototype_class_definition, 0,
- sizeof(interface_data->prototype_class_definition));
- memset(&interface_data->interface_object_class_definition, 0,
- sizeof(interface_data->interface_object_class_definition));
-
- JSClass* instance_class = &interface_data->instance_class_definition;
- const int kGlobalFlags = 0;
- instance_class->name = "ExtendedIDLAttributesInterface";
- instance_class->flags = kGlobalFlags | JSCLASS_HAS_PRIVATE;
- instance_class->addProperty = JS_PropertyStub;
- instance_class->delProperty = JS_DeletePropertyStub;
- instance_class->getProperty = JS_PropertyStub;
- instance_class->setProperty = JS_StrictPropertyStub;
- instance_class->enumerate = JS_EnumerateStub;
- instance_class->resolve = JS_ResolveStub;
- instance_class->convert = JS_ConvertStub;
- // Function to be called before on object of this class is garbage collected.
- instance_class->finalize = &WrapperPrivate::Finalizer;
- // Called to trace objects that can be referenced from this object.
- instance_class->trace = &WrapperPrivate::Trace;
-
- JSClass* prototype_class = &interface_data->prototype_class_definition;
- prototype_class->name = "ExtendedIDLAttributesInterfacePrototype";
- prototype_class->flags = 0;
- prototype_class->addProperty = JS_PropertyStub;
- prototype_class->delProperty = JS_DeletePropertyStub;
- prototype_class->getProperty = JS_PropertyStub;
- prototype_class->setProperty = JS_StrictPropertyStub;
- prototype_class->enumerate = JS_EnumerateStub;
- prototype_class->resolve = JS_ResolveStub;
- prototype_class->convert = JS_ConvertStub;
-
- JSClass* interface_object_class =
- &interface_data->interface_object_class_definition;
- interface_object_class->name = "ExtendedIDLAttributesInterfaceConstructor";
- interface_object_class->flags = 0;
- interface_object_class->addProperty = JS_PropertyStub;
- interface_object_class->delProperty = JS_DeletePropertyStub;
- interface_object_class->getProperty = JS_PropertyStub;
- interface_object_class->setProperty = JS_StrictPropertyStub;
- interface_object_class->enumerate = JS_EnumerateStub;
- interface_object_class->resolve = JS_ResolveStub;
- interface_object_class->convert = JS_ConvertStub;
- interface_object_class->hasInstance = &HasInstance;
- return interface_data;
-}
-
-JSBool get_default(
- JSContext* context, JS::HandleObject object, JS::HandleId id,
- JS::MutableHandleValue vp) {
- const JSClass* proto_class =
- MozjsExtendedIDLAttributesInterface::PrototypeClass(context);
- if (proto_class == JS_GetClass(object)) {
- // Simply returns true if the object is this class's prototype object.
- // There is no need to return any value due to the object is not a platform
- // object. The execution reaches here when Object.getOwnPropertyDescriptor
- // gets called on native object prototypes.
- return true;
- }
-
- MozjsGlobalEnvironment* global_environment =
- static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context));
- WrapperFactory* wrapper_factory = global_environment->wrapper_factory();
- if (!wrapper_factory->DoesObjectImplementInterface(
- object, base::GetTypeId<ExtendedIDLAttributesInterface>())) {
- MozjsExceptionState exception(context);
- exception.SetSimpleException(script::kDoesNotImplementInterface);
- return false;
- }
- MozjsExceptionState exception_state(context);
- JS::RootedValue result_value(context);
-
- WrapperPrivate* wrapper_private =
- WrapperPrivate::GetFromObject(context, object);
- ExtendedIDLAttributesInterface* impl =
- wrapper_private->wrappable<ExtendedIDLAttributesInterface>().get();
-
- if (!exception_state.is_exception_set()) {
- ToJSValue(context,
- impl->attribute_default(),
- &result_value);
- }
- if (!exception_state.is_exception_set()) {
- vp.set(result_value);
- }
- return !exception_state.is_exception_set();
-}
-
-JSBool set_default(
- JSContext* context, JS::HandleObject object, JS::HandleId id,
- JSBool strict, JS::MutableHandleValue vp) {
- const JSClass* proto_class =
- MozjsExtendedIDLAttributesInterface::PrototypeClass(context);
- if (proto_class == JS_GetClass(object)) {
- // Simply returns true if the object is this class's prototype object.
- // There is no need to return any value due to the object is not a platform
- // object. The execution reaches here when Object.getOwnPropertyDescriptor
- // gets called on native object prototypes.
- return true;
- }
-
- MozjsGlobalEnvironment* global_environment =
- static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context));
- WrapperFactory* wrapper_factory = global_environment->wrapper_factory();
- if (!wrapper_factory->DoesObjectImplementInterface(
- object, base::GetTypeId<ExtendedIDLAttributesInterface>())) {
- MozjsExceptionState exception(context);
- exception.SetSimpleException(script::kDoesNotImplementInterface);
- return false;
- }
- MozjsExceptionState exception_state(context);
- JS::RootedValue result_value(context);
-
- WrapperPrivate* wrapper_private =
- WrapperPrivate::GetFromObject(context, object);
- ExtendedIDLAttributesInterface* impl =
- wrapper_private->wrappable<ExtendedIDLAttributesInterface>().get();
- TypeTraits<bool >::ConversionType value;
- FromJSValue(context, vp, kNoConversionFlags, &exception_state,
- &value);
- if (exception_state.is_exception_set()) {
- return false;
- }
-
- impl->set_attribute_default(value);
- result_value.set(JS::UndefinedHandleValue);
- return !exception_state.is_exception_set();
-}
-
-JSBool fcn_callWithSettings(
- JSContext* context, uint32_t argc, JS::Value *vp) {
- JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
- // Compute the 'this' value.
- JS::RootedValue this_value(context, JS_ComputeThis(context, vp));
- // 'this' should be an object.
- JS::RootedObject object(context);
- if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) {
- return false;
- }
- if (!JS_ValueToObject(context, this_value, object.address())) {
- NOTREACHED();
- return false;
- }
- const JSClass* proto_class =
- MozjsExtendedIDLAttributesInterface::PrototypeClass(context);
- if (proto_class == JS_GetClass(object)) {
- // Simply returns true if the object is this class's prototype object.
- // There is no need to return any value due to the object is not a platform
- // object. The execution reaches here when Object.getOwnPropertyDescriptor
- // gets called on native object prototypes.
- return true;
- }
-
- MozjsGlobalEnvironment* global_environment =
- static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context));
- WrapperFactory* wrapper_factory = global_environment->wrapper_factory();
- if (!wrapper_factory->DoesObjectImplementInterface(
- object, base::GetTypeId<ExtendedIDLAttributesInterface>())) {
- MozjsExceptionState exception(context);
- exception.SetSimpleException(script::kDoesNotImplementInterface);
- return false;
- }
- MozjsExceptionState exception_state(context);
- JS::RootedValue result_value(context);
-
- WrapperPrivate* wrapper_private =
- WrapperPrivate::GetFromObject(context, object);
- ExtendedIDLAttributesInterface* impl =
- wrapper_private->wrappable<ExtendedIDLAttributesInterface>().get();
- MozjsGlobalEnvironment* callwith_global_environment =
- static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context));
-
- impl->CallWithSettings(callwith_global_environment->GetEnvironmentSettings());
- result_value.set(JS::UndefinedHandleValue);
- return !exception_state.is_exception_set();
-}
-
-JSBool fcn_clampArgument(
- JSContext* context, uint32_t argc, JS::Value *vp) {
- JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
- // Compute the 'this' value.
- JS::RootedValue this_value(context, JS_ComputeThis(context, vp));
- // 'this' should be an object.
- JS::RootedObject object(context);
- if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) {
- return false;
- }
- if (!JS_ValueToObject(context, this_value, object.address())) {
- NOTREACHED();
- return false;
- }
- const JSClass* proto_class =
- MozjsExtendedIDLAttributesInterface::PrototypeClass(context);
- if (proto_class == JS_GetClass(object)) {
- // Simply returns true if the object is this class's prototype object.
- // There is no need to return any value due to the object is not a platform
- // object. The execution reaches here when Object.getOwnPropertyDescriptor
- // gets called on native object prototypes.
- return true;
- }
-
- MozjsGlobalEnvironment* global_environment =
- static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context));
- WrapperFactory* wrapper_factory = global_environment->wrapper_factory();
- if (!wrapper_factory->DoesObjectImplementInterface(
- object, base::GetTypeId<ExtendedIDLAttributesInterface>())) {
- MozjsExceptionState exception(context);
- exception.SetSimpleException(script::kDoesNotImplementInterface);
- return false;
- }
- MozjsExceptionState exception_state(context);
- JS::RootedValue result_value(context);
-
- WrapperPrivate* wrapper_private =
- WrapperPrivate::GetFromObject(context, object);
- ExtendedIDLAttributesInterface* impl =
- wrapper_private->wrappable<ExtendedIDLAttributesInterface>().get();
- const size_t kMinArguments = 1;
- if (args.length() < kMinArguments) {
- exception_state.SetSimpleException(script::kInvalidNumberOfArguments);
- return false;
- }
- // Non-optional arguments
- TypeTraits<uint16_t >::ConversionType arg;
-
- DCHECK_LT(0, args.length());
- JS::RootedValue non_optional_value0(
- context, args[0]);
- FromJSValue(context,
- non_optional_value0,
- (kConversionFlagClamped),
- &exception_state, &arg);
- if (exception_state.is_exception_set()) {
- return false;
- }
-
- impl->ClampArgument(arg);
- result_value.set(JS::UndefinedHandleValue);
- return !exception_state.is_exception_set();
-}
-
-
-const JSPropertySpec prototype_properties[] = {
- { // Read/Write property
- "default", 0,
- JSPROP_SHARED | JSPROP_ENUMERATE,
- JSOP_WRAPPER(&get_default),
- JSOP_WRAPPER(&set_default),
- },
- JS_PS_END
-};
-
-const JSFunctionSpec prototype_functions[] = {
- {
- "callWithSettings",
- JSOP_WRAPPER(&fcn_callWithSettings),
- 0,
- JSPROP_ENUMERATE,
- NULL,
- },
- {
- "clampArgument",
- JSOP_WRAPPER(&fcn_clampArgument),
- 1,
- JSPROP_ENUMERATE,
- NULL,
- },
- JS_FS_END
-};
-
-const JSPropertySpec interface_object_properties[] = {
- JS_PS_END
-};
-
-const JSFunctionSpec interface_object_functions[] = {
- JS_FS_END
-};
-
-const JSPropertySpec own_properties[] = {
- JS_PS_END
-};
-
-void InitializePrototypeAndInterfaceObject(
- InterfaceData* interface_data, JSContext* context,
- JS::HandleObject global_object) {
- DCHECK(!interface_data->prototype);
- DCHECK(!interface_data->interface_object);
- DCHECK(JS_IsGlobalObject(global_object));
-
- JS::RootedObject parent_prototype(
- context, JS_GetObjectPrototype(context, global_object));
- DCHECK(parent_prototype);
-
- // Create the Prototype object.
- interface_data->prototype = JS_NewObjectWithGivenProto(
- context, &interface_data->prototype_class_definition, parent_prototype,
- NULL);
- bool success = JS_DefineProperties(
- context, interface_data->prototype, prototype_properties);
- DCHECK(success);
- success = JS_DefineFunctions(
- context, interface_data->prototype, prototype_functions);
- DCHECK(success);
-
- JS::RootedObject function_prototype(
- context, JS_GetFunctionPrototype(context, global_object));
- DCHECK(function_prototype);
- // Create the Interface object.
- interface_data->interface_object = JS_NewObjectWithGivenProto(
- context, &interface_data->interface_object_class_definition,
- function_prototype, NULL);
-
- // Add the InterfaceObject.name property.
- JS::RootedObject rooted_interface_object(
- context, interface_data->interface_object);
- JS::RootedValue name_value(context);
- const char name[] =
- "ExtendedIDLAttributesInterface";
- name_value.setString(JS_NewStringCopyZ(context, name));
- success =
- JS_DefineProperty(context, rooted_interface_object, "name", name_value,
- JS_PropertyStub, JS_StrictPropertyStub,
- JSPROP_READONLY);
- DCHECK(success);
-
- // Define interface object properties (including constants).
- success = JS_DefineProperties(context, rooted_interface_object,
- interface_object_properties);
- DCHECK(success);
- // Define interface object functions (static).
- success = JS_DefineFunctions(context, rooted_interface_object,
- interface_object_functions);
- DCHECK(success);
-
-
- // Set the Prototype.constructor and Constructor.prototype properties.
- DCHECK(interface_data->interface_object);
- DCHECK(interface_data->prototype);
- JS::RootedObject rooted_prototype(context, interface_data->prototype);
- success = JS_LinkConstructorAndPrototype(
- context,
- rooted_interface_object,
- rooted_prototype);
- DCHECK(success);
-}
-
-InterfaceData* GetInterfaceData(JSContext* context) {
- MozjsGlobalEnvironment* global_environment =
- static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context));
- // Use the address of the properties definition for this interface as a
- // unique key for looking up the InterfaceData for this interface.
- intptr_t key = reinterpret_cast<intptr_t>(&own_properties);
- InterfaceData* interface_data = global_environment->GetInterfaceData(key);
- if (!interface_data) {
- interface_data = CreateCachedInterfaceData();
- DCHECK(interface_data);
- global_environment->CacheInterfaceData(key, interface_data);
- DCHECK_EQ(interface_data, global_environment->GetInterfaceData(key));
- }
- return interface_data;
-}
-
-} // namespace
-
-// static
-JSObject* MozjsExtendedIDLAttributesInterface::CreateProxy(
- JSContext* context, const scoped_refptr<Wrappable>& wrappable) {
- DCHECK(MozjsGlobalEnvironment::GetFromContext(context));
- JS::RootedObject global_object(
- context,
- MozjsGlobalEnvironment::GetFromContext(context)->global_object());
- DCHECK(global_object);
-
- InterfaceData* interface_data = GetInterfaceData(context);
- JS::RootedObject prototype(context, GetPrototype(context, global_object));
- DCHECK(prototype);
- JS::RootedObject new_object(context, JS_NewObjectWithGivenProto(
- context, &interface_data->instance_class_definition, prototype, NULL));
- DCHECK(new_object);
- JS::RootedObject proxy(context,
- ProxyHandler::NewProxy(context, new_object, prototype, NULL,
- proxy_handler.Pointer()));
- WrapperPrivate::AddPrivateData(context, proxy, wrappable);
- return proxy;
-}
-
-//static
-const JSClass* MozjsExtendedIDLAttributesInterface::PrototypeClass(
- JSContext* context) {
- DCHECK(MozjsGlobalEnvironment::GetFromContext(context));
- JS::RootedObject global_object(
- context,
- MozjsGlobalEnvironment::GetFromContext(context)->global_object());
- DCHECK(global_object);
-
- JS::RootedObject prototype(context, GetPrototype(context, global_object));
- JSClass* proto_class = JS_GetClass(*prototype.address());
- return proto_class;
-}
-
-// static
-JSObject* MozjsExtendedIDLAttributesInterface::GetPrototype(
- JSContext* context, JS::HandleObject global_object) {
- DCHECK(JS_IsGlobalObject(global_object));
-
- InterfaceData* interface_data = GetInterfaceData(context);
- if (!interface_data->prototype) {
- // Create new prototype that has all the props and methods
- InitializePrototypeAndInterfaceObject(
- interface_data, context, global_object);
- }
- DCHECK(interface_data->prototype);
- return interface_data->prototype;
-}
-
-// static
-JSObject* MozjsExtendedIDLAttributesInterface::GetInterfaceObject(
- JSContext* context, JS::HandleObject global_object) {
- DCHECK(JS_IsGlobalObject(global_object));
-
- InterfaceData* interface_data = GetInterfaceData(context);
- if (!interface_data->interface_object) {
- InitializePrototypeAndInterfaceObject(
- interface_data, context, global_object);
- }
- DCHECK(interface_data->interface_object);
- return interface_data->interface_object;
-}
-
-
-namespace {
-} // namespace
-
-
-} // namespace testing
-} // namespace bindings
-} // namespace cobalt
diff --git a/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_extended_idl_attributes_interface.h b/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_extended_idl_attributes_interface.h
deleted file mode 100644
index 6d676fb..0000000
--- a/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_extended_idl_attributes_interface.h
+++ /dev/null
@@ -1,52 +0,0 @@
-// Copyright 2017 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/mozjs/templates/interface.h.template
-
-#ifndef MozjsExtendedIDLAttributesInterface_h
-#define MozjsExtendedIDLAttributesInterface_h
-
-#include "base/hash_tables.h"
-#include "base/lazy_instance.h"
-#include "base/memory/ref_counted.h"
-#include "base/threading/thread_checker.h"
-#include "cobalt/base/polymorphic_downcast.h"
-#include "cobalt/script/wrappable.h"
-#include "cobalt/bindings/testing/extended_idl_attributes_interface.h"
-
-#include "third_party/mozjs/js/src/jsapi.h"
-
-namespace cobalt {
-namespace bindings {
-namespace testing {
-
-class MozjsExtendedIDLAttributesInterface {
- public:
- static JSObject* CreateProxy(JSContext* context,
- const scoped_refptr<script::Wrappable>& wrappable);
- static const JSClass* PrototypeClass(JSContext* context);
- static JSObject* GetPrototype(JSContext* context,
- JS::HandleObject global_object);
- static JSObject* GetInterfaceObject(JSContext* context,
- JS::HandleObject global_object);
-};
-
-} // namespace testing
-} // namespace bindings
-} // namespace cobalt
-
-#endif // MozjsExtendedIDLAttributesInterface_h
diff --git a/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_garbage_collection_test_interface.cc b/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_garbage_collection_test_interface.cc
deleted file mode 100644
index eb0a945..0000000
--- a/src/cobalt/bindings/generated/mozjs/testing/cobalt/bindings/testing/mozjs_garbage_collection_test_interface.cc
+++ /dev/null
@@ -1,574 +0,0 @@
-// Copyright 2017 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/mozjs/templates/interface.cc.template
-
-#include "cobalt/bindings/testing/mozjs_garbage_collection_test_interface.h"
-
-#include "base/debug/trace_event.h"
-#include "cobalt/base/polymorphic_downcast.h"
-#include "cobalt/script/global_environment.h"
-#include "cobalt/script/opaque_handle.h"
-#include "cobalt/script/script_value.h"
-#include "cobalt/bindings/testing/garbage_collection_test_interface.h"
-#include "cobalt/bindings/testing/mozjs_garbage_collection_test_interface.h"
-
-#include "mozjs_gen_type_conversion.h"
-
-#include "base/lazy_instance.h"
-#include "cobalt/script/exception_state.h"
-#include "cobalt/script/mozjs/callback_function_conversion.h"
-#include "cobalt/script/mozjs/conversion_helpers.h"
-#include "cobalt/script/mozjs/mozjs_callback_function.h"
-#include "cobalt/script/mozjs/mozjs_exception_state.h"
-#include "cobalt/script/mozjs/mozjs_global_environment.h"
-#include "cobalt/script/mozjs/mozjs_object_handle.h"
-#include "cobalt/script/mozjs/mozjs_property_enumerator.h"
-#include "cobalt/script/mozjs/mozjs_user_object_holder.h"
-#include "cobalt/script/mozjs/mozjs_value_handle.h"
-#include "cobalt/script/mozjs/native_promise.h"
-#include "cobalt/script/mozjs/proxy_handler.h"
-#include "cobalt/script/mozjs/type_traits.h"
-#include "cobalt/script/mozjs/wrapper_factory.h"
-#include "cobalt/script/mozjs/wrapper_private.h"
-#include "cobalt/script/property_enumerator.h"
-#include "cobalt/script/sequence.h"
-#include "third_party/mozjs/js/src/jsapi.h"
-#include "third_party/mozjs/js/src/jsfriendapi.h"
-
-namespace {
-using cobalt::bindings::testing::GarbageCollectionTestInterface;
-using cobalt::bindings::testing::MozjsGarbageCollectionTestInterface;
-using cobalt::bindings::testing::GarbageCollectionTestInterface;
-using cobalt::bindings::testing::MozjsGarbageCollectionTestInterface;
-using cobalt::script::CallbackInterfaceTraits;
-using cobalt::script::GlobalEnvironment;
-using cobalt::script::OpaqueHandle;
-using cobalt::script::OpaqueHandleHolder;
-using cobalt::script::ScriptValue;
-using cobalt::script::ValueHandle;
-using cobalt::script::Wrappable;
-
-using cobalt::script::CallbackFunction;
-using cobalt::script::CallbackInterfaceTraits;
-using cobalt::script::ExceptionState;
-using cobalt::script::Wrappable;
-using cobalt::script::mozjs::FromJSValue;
-using cobalt::script::mozjs::InterfaceData;
-using cobalt::script::mozjs::MozjsCallbackFunction;
-using cobalt::script::mozjs::MozjsExceptionState;
-using cobalt::script::mozjs::MozjsGlobalEnvironment;
-using cobalt::script::mozjs::MozjsPropertyEnumerator;
-using cobalt::script::mozjs::MozjsUserObjectHolder;
-using cobalt::script::mozjs::ProxyHandler;
-using cobalt::script::mozjs::ToJSValue;
-using cobalt::script::mozjs::TypeTraits;
-using cobalt::script::mozjs::WrapperFactory;
-using cobalt::script::mozjs::WrapperPrivate;
-using cobalt::script::mozjs::kConversionFlagClamped;
-using cobalt::script::mozjs::kConversionFlagNullable;
-using cobalt::script::mozjs::kConversionFlagRestricted;
-using cobalt::script::mozjs::kConversionFlagTreatNullAsEmptyString;
-using cobalt::script::mozjs::kConversionFlagTreatUndefinedAsEmptyString;
-using cobalt::script::mozjs::kNoConversionFlags;
-} // namespace
-
-namespace cobalt {
-namespace bindings {
-namespace testing {
-
-namespace {
-
-class MozjsGarbageCollectionTestInterfaceHandler : public ProxyHandler {
- public:
- MozjsGarbageCollectionTestInterfaceHandler()
- : ProxyHandler(indexed_property_hooks, named_property_hooks) {}
-
- private:
- static NamedPropertyHooks named_property_hooks;
- static IndexedPropertyHooks indexed_property_hooks;