blob: f8e366d40580e2ff3be20b642803e5991dfdcda6 [file] [log] [blame]
// 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/mozjs45/templates/interface.cc.template
#include "cobalt/bindings/testing/mozjs_operations_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/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-45/callback_function_conversion.h"
#include "cobalt/script/mozjs-45/conversion_helpers.h"
#include "cobalt/script/mozjs-45/mozjs_callback_function.h"
#include "cobalt/script/mozjs-45/mozjs_exception_state.h"
#include "cobalt/script/mozjs-45/mozjs_global_environment.h"
#include "cobalt/script/mozjs-45/mozjs_object_handle.h"
#include "cobalt/script/mozjs-45/mozjs_property_enumerator.h"
#include "cobalt/script/mozjs-45/mozjs_user_object_holder.h"
#include "cobalt/script/mozjs-45/mozjs_value_handle.h"
#include "cobalt/script/mozjs-45/native_promise.h"
#include "cobalt/script/mozjs-45/proxy_handler.h"
#include "cobalt/script/mozjs-45/type_traits.h"
#include "cobalt/script/mozjs-45/wrapper_factory.h"
#include "cobalt/script/mozjs-45/wrapper_private.h"
#include "cobalt/script/property_enumerator.h"
#include "cobalt/script/sequence.h"
#include "third_party/mozjs-45/js/src/jsapi.h"
#include "third_party/mozjs-45/js/src/jsfriendapi.h"
namespace {
using cobalt::bindings::testing::OperationsTestInterface;
using cobalt::bindings::testing::MozjsOperationsTestInterface;
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 MozjsOperationsTestInterfaceHandler : public ProxyHandler {
public:
MozjsOperationsTestInterfaceHandler()
: ProxyHandler(indexed_property_hooks, named_property_hooks) {}
private:
static NamedPropertyHooks named_property_hooks;
static IndexedPropertyHooks indexed_property_hooks;
};
ProxyHandler::NamedPropertyHooks
MozjsOperationsTestInterfaceHandler::named_property_hooks = {
NULL,
NULL,
NULL,
NULL,
NULL,
};
ProxyHandler::IndexedPropertyHooks
MozjsOperationsTestInterfaceHandler::indexed_property_hooks = {
NULL,
NULL,
NULL,
NULL,
NULL,
};
static base::LazyInstance<MozjsOperationsTestInterfaceHandler>
proxy_handler;
bool HasInstance(JSContext *context, JS::HandleObject type,
JS::MutableHandleValue vp, bool *success) {
JS::RootedObject global_object(
context, JS_GetGlobalForObject(context, type));
DCHECK(global_object);
JS::RootedObject prototype(
context, MozjsOperationsTestInterface::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;
}
const JSClass instance_class_definition = {
"OperationsTestInterface",
0 | JSCLASS_HAS_PRIVATE,
NULL, // addProperty
NULL, // delProperty
NULL, // getProperty
NULL, // setProperty
NULL, // enumerate
NULL, // resolve
NULL, // mayResolve
&WrapperPrivate::Finalizer, // finalize
NULL, // call
NULL, // hasInstance
NULL, // construct
&WrapperPrivate::Trace, // trace
};
const JSClass prototype_class_definition = {
"OperationsTestInterfacePrototype",
};
const JSClass interface_object_class_definition = {
"OperationsTestInterfaceConstructor",
0,
NULL, // addProperty
NULL, // delProperty
NULL, // getProperty
NULL, // setProperty
NULL, // enumerate
NULL, // resolve
NULL, // mayResolve
NULL, // finalize
NULL, // call
&HasInstance,
NULL,
};
bool fcn_longFunctionNoArgs(
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)) {
NOTREACHED();
return false;
}
const JSClass* proto_class =
MozjsOperationsTestInterface::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<OperationsTestInterface>())) {
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);
OperationsTestInterface* impl =
wrapper_private->wrappable<OperationsTestInterface>().get();
if (!exception_state.is_exception_set()) {
ToJSValue(context,
impl->LongFunctionNoArgs(),
&result_value);
}
if (!exception_state.is_exception_set()) {
args.rval().set(result_value);
}
return !exception_state.is_exception_set();
}
bool fcn_objectFunctionNoArgs(
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)) {
NOTREACHED();
return false;
}
const JSClass* proto_class =
MozjsOperationsTestInterface::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<OperationsTestInterface>())) {
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);
OperationsTestInterface* impl =
wrapper_private->wrappable<OperationsTestInterface>().get();
if (!exception_state.is_exception_set()) {
ToJSValue(context,
impl->ObjectFunctionNoArgs(),
&result_value);
}
if (!exception_state.is_exception_set()) {
args.rval().set(result_value);
}
return !exception_state.is_exception_set();
}
bool fcn_optionalArgumentWithDefault(
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)) {
NOTREACHED();
return false;
}
const JSClass* proto_class =
MozjsOperationsTestInterface::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<OperationsTestInterface>())) {
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);
OperationsTestInterface* impl =
wrapper_private->wrappable<OperationsTestInterface>().get();
// Optional arguments with default values
TypeTraits<double >::ConversionType arg1 =
2.718;
size_t num_set_arguments = 1;
if (args.length() > 0) {
JS::RootedValue optional_value0(
context, args[0]);
FromJSValue(context,
optional_value0,
(kConversionFlagRestricted),
&exception_state,
&arg1);
if (exception_state.is_exception_set()) {
return false;
}
}
impl->OptionalArgumentWithDefault(arg1);
result_value.set(JS::UndefinedHandleValue);
return !exception_state.is_exception_set();
}
bool fcn_optionalArguments(
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)) {
NOTREACHED();
return false;
}
const JSClass* proto_class =
MozjsOperationsTestInterface::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<OperationsTestInterface>())) {
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);
OperationsTestInterface* impl =
wrapper_private->wrappable<OperationsTestInterface>().get();
const size_t kMinArguments = 1;
if (args.length() < kMinArguments) {
exception_state.SetSimpleException(script::kInvalidNumberOfArguments);
return false;
}
// Non-optional arguments
TypeTraits<int32_t >::ConversionType arg1;
// Optional arguments
TypeTraits<int32_t >::ConversionType arg2;
TypeTraits<int32_t >::ConversionType arg3;
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;
}
size_t num_set_arguments = 1;
if (args.length() > 1) {
JS::RootedValue optional_value0(
context, args[1]);
FromJSValue(context,
optional_value0,
kNoConversionFlags,
&exception_state,
&arg2);
if (exception_state.is_exception_set()) {
return false;
}
++num_set_arguments;
}
if (args.length() > 2) {
JS::RootedValue optional_value1(
context, args[2]);
FromJSValue(context,
optional_value1,
kNoConversionFlags,
&exception_state,
&arg3);
if (exception_state.is_exception_set()) {
return false;
}
++num_set_arguments;
}
switch (num_set_arguments) {
case 1:
{
impl->OptionalArguments(arg1);
result_value.set(JS::UndefinedHandleValue);
return !exception_state.is_exception_set();
}
break;
case 2:
{
impl->OptionalArguments(arg1, arg2);
result_value.set(JS::UndefinedHandleValue);
return !exception_state.is_exception_set();
}
break;
case 3:
{
impl->OptionalArguments(arg1, arg2, arg3);
result_value.set(JS::UndefinedHandleValue);
return !exception_state.is_exception_set();
}
break;
default:
NOTREACHED();
return false;
}
}
bool fcn_optionalNullableArgumentsWithDefaults(
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)) {
NOTREACHED();
return false;
}
const JSClass* proto_class =
MozjsOperationsTestInterface::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<OperationsTestInterface>())) {
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);
OperationsTestInterface* impl =
wrapper_private->wrappable<OperationsTestInterface>().get();
// Optional arguments with default values
TypeTraits<base::optional<bool > >::ConversionType arg1 =
base::nullopt;
TypeTraits<scoped_refptr<ArbitraryInterface> >::ConversionType arg2 =
NULL;
size_t num_set_arguments = 2;
if (args.length() > 0) {
JS::RootedValue optional_value0(
context, args[0]);
FromJSValue(context,
optional_value0,
(kConversionFlagNullable),
&exception_state,
&arg1);
if (exception_state.is_exception_set()) {
return false;
}
}
if (args.length() > 1) {
JS::RootedValue optional_value1(
context, args[1]);
FromJSValue(context,
optional_value1,
(kConversionFlagNullable),
&exception_state,
&arg2);
if (exception_state.is_exception_set()) {
return false;
}
}
impl->OptionalNullableArgumentsWithDefaults(arg1, arg2);
result_value.set(JS::UndefinedHandleValue);
return !exception_state.is_exception_set();
}
bool fcn_overloadedFunction1(
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)) {
NOTREACHED();
return false;
}
const JSClass* proto_class =
MozjsOperationsTestInterface::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<OperationsTestInterface>())) {
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);
OperationsTestInterface* impl =
wrapper_private->wrappable<OperationsTestInterface>().get();
impl->OverloadedFunction();
result_value.set(JS::UndefinedHandleValue);
return !exception_state.is_exception_set();
}
bool fcn_overloadedFunction2(
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)) {
NOTREACHED();
return false;
}
const JSClass* proto_class =
MozjsOperationsTestInterface::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<OperationsTestInterface>())) {
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);
OperationsTestInterface* impl =
wrapper_private->wrappable<OperationsTestInterface>().get();
const size_t kMinArguments = 1;
if (args.length() < kMinArguments) {
exception_state.SetSimpleException(script::kInvalidNumberOfArguments);
return false;
}
// Non-optional arguments
TypeTraits<int32_t >::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;
}
impl->OverloadedFunction(arg);
result_value.set(JS::UndefinedHandleValue);
return !exception_state.is_exception_set();
}
bool fcn_overloadedFunction3(
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)) {
NOTREACHED();
return false;
}
const JSClass* proto_class =
MozjsOperationsTestInterface::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<OperationsTestInterface>())) {
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);
OperationsTestInterface* impl =
wrapper_private->wrappable<OperationsTestInterface>().get();
const size_t kMinArguments = 1;
if (args.length() < kMinArguments) {
exception_state.SetSimpleException(script::kInvalidNumberOfArguments);
return false;
}
// Non-optional arguments
TypeTraits<std::string >::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;
}
impl->OverloadedFunction(arg);
result_value.set(JS::UndefinedHandleValue);
return !exception_state.is_exception_set();
}
bool fcn_overloadedFunction4(
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)) {
NOTREACHED();
return false;
}
const JSClass* proto_class =
MozjsOperationsTestInterface::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<OperationsTestInterface>())) {
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);
OperationsTestInterface* impl =
wrapper_private->wrappable<OperationsTestInterface>().get();
const size_t kMinArguments = 3;
if (args.length() < kMinArguments) {
exception_state.SetSimpleException(script::kInvalidNumberOfArguments);
return false;
}
// Non-optional arguments
TypeTraits<int32_t >::ConversionType arg1;
TypeTraits<int32_t >::ConversionType arg2;
TypeTraits<int32_t >::ConversionType arg3;
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;
}
DCHECK_LT(2, args.length());
JS::RootedValue non_optional_value2(
context, args[2]);
FromJSValue(context,
non_optional_value2,
kNoConversionFlags,
&exception_state, &arg3);
if (exception_state.is_exception_set()) {
return false;
}
impl->OverloadedFunction(arg1, arg2, arg3);
result_value.set(JS::UndefinedHandleValue);
return !exception_state.is_exception_set();
}
bool fcn_overloadedFunction5(
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)) {
NOTREACHED();
return false;
}
const JSClass* proto_class =
MozjsOperationsTestInterface::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<OperationsTestInterface>())) {
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);
OperationsTestInterface* impl =
wrapper_private->wrappable<OperationsTestInterface>().get();
const size_t kMinArguments = 3;
if (args.length() < kMinArguments) {
exception_state.SetSimpleException(script::kInvalidNumberOfArguments);
return false;
}
// Non-optional arguments
TypeTraits<int32_t >::ConversionType arg1;
TypeTraits<int32_t >::ConversionType arg2;
TypeTraits<scoped_refptr<ArbitraryInterface> >::ConversionType arg3;
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;
}
DCHECK_LT(2, args.length());
JS::RootedValue non_optional_value2(
context, args[2]);
FromJSValue(context,
non_optional_value2,
kNoConversionFlags,
&exception_state, &arg3);
if (exception_state.is_exception_set()) {
return false;
}
impl->OverloadedFunction(arg1, arg2, arg3);
result_value.set(JS::UndefinedHandleValue);
return !exception_state.is_exception_set();
}
bool fcn_overloadedFunction(
JSContext* context, uint32_t 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 fcn_overloadedFunction1(
context, argc, vp);
}
break;
}
case(1): {
// Overload resolution algorithm details found here:
// http://heycam.github.io/webidl/#dfn-overload-resolution-algorithm
JS::RootedValue arg(context, args[0]);
MozjsGlobalEnvironment* global_environment =
static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context));
WrapperFactory* wrapper_factory = global_environment->wrapper_factory();
JS::RootedObject object(context);
if (arg.isObject()) {
object = JS::RootedObject(context, &arg.toObject());
}
if (arg.isNumber()) {
return fcn_overloadedFunction2(
context, argc, vp);
}
if (true) {
return fcn_overloadedFunction3(
context, argc, vp);
}
if (true) {
return fcn_overloadedFunction2(
context, argc, vp);
}
break;
}
case(3): {
// Overload resolution algorithm details found here:
// http://heycam.github.io/webidl/#dfn-overload-resolution-algorithm
JS::RootedValue arg(context, args[2]);
MozjsGlobalEnvironment* global_environment =
static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context));
WrapperFactory* wrapper_factory = global_environment->wrapper_factory();
JS::RootedObject object(context);
if (arg.isObject()) {
object = JS::RootedObject(context, &arg.toObject());
}
if (arg.isObject() ? wrapper_factory->DoesObjectImplementInterface(
object, base::GetTypeId<ArbitraryInterface>()) :
false) {
return fcn_overloadedFunction5(
context, argc, vp);
}
if (true) {
return fcn_overloadedFunction4(
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;
}
bool fcn_overloadedNullable1(
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)) {
NOTREACHED();
return false;
}
const JSClass* proto_class =
MozjsOperationsTestInterface::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<OperationsTestInterface>())) {
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);
OperationsTestInterface* impl =
wrapper_private->wrappable<OperationsTestInterface>().get();
const size_t kMinArguments = 1;
if (args.length() < kMinArguments) {
exception_state.SetSimpleException(script::kInvalidNumberOfArguments);
return false;
}
// Non-optional arguments
TypeTraits<int32_t >::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;
}
impl->OverloadedNullable(arg);
result_value.set(JS::UndefinedHandleValue);
return !exception_state.is_exception_set();
}
bool fcn_overloadedNullable2(
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)) {
NOTREACHED();
return false;
}
const JSClass* proto_class =
MozjsOperationsTestInterface::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<OperationsTestInterface>())) {
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);
OperationsTestInterface* impl =
wrapper_private->wrappable<OperationsTestInterface>().get();
const size_t kMinArguments = 1;
if (args.length() < kMinArguments) {
exception_state.SetSimpleException(script::kInvalidNumberOfArguments);
return false;
}
// Non-optional arguments
TypeTraits<base::optional<bool > >::ConversionType arg;
DCHECK_LT(0, args.length());
JS::RootedValue non_optional_value0(
context, args[0]);
FromJSValue(context,
non_optional_value0,
(kConversionFlagNullable),
&exception_state, &arg);
if (exception_state.is_exception_set()) {
return false;
}
impl->OverloadedNullable(arg);
result_value.set(JS::UndefinedHandleValue);
return !exception_state.is_exception_set();
}
bool fcn_overloadedNullable(
JSContext* context, uint32_t argc, JS::Value *vp) {
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
switch(argc) {
case(1): {
// Overload resolution algorithm details found here:
// http://heycam.github.io/webidl/#dfn-overload-resolution-algorithm
JS::RootedValue arg(context, args[0]);
MozjsGlobalEnvironment* global_environment =
static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context));
WrapperFactory* wrapper_factory = global_environment->wrapper_factory();
JS::RootedObject object(context);
if (arg.isObject()) {
object = JS::RootedObject(context, &arg.toObject());
}
if (arg.isNullOrUndefined()) {
return fcn_overloadedNullable2(
context, argc, vp);
}
if (true) {
return fcn_overloadedNullable1(
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;
}
bool fcn_stringFunctionNoArgs(
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)) {
NOTREACHED();
return false;
}
const JSClass* proto_class =
MozjsOperationsTestInterface::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<OperationsTestInterface>())) {
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);
OperationsTestInterface* impl =
wrapper_private->wrappable<OperationsTestInterface>().get();
if (!exception_state.is_exception_set()) {
ToJSValue(context,
impl->StringFunctionNoArgs(),
&result_value);
}
if (!exception_state.is_exception_set()) {
args.rval().set(result_value);
}
return !exception_state.is_exception_set();
}
bool fcn_variadicPrimitiveArguments(
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)) {
NOTREACHED();
return false;
}
const JSClass* proto_class =
MozjsOperationsTestInterface::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<OperationsTestInterface>())) {
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);
OperationsTestInterface* impl =
wrapper_private->wrappable<OperationsTestInterface>().get();
// Variadic argument
TypeTraits<std::vector<int32_t> >::ConversionType bools;
// Get variadic arguments.
const size_t kFirstVariadicArgIndex = 0;
if (args.length() > kFirstVariadicArgIndex) {
bools.resize(args.length() - kFirstVariadicArgIndex);
for (int i = 0; i + kFirstVariadicArgIndex < args.length(); ++i) {
JS::RootedValue variadic_argument_value(
context, args[i + kFirstVariadicArgIndex]);
FromJSValue(context,
variadic_argument_value,
kNoConversionFlags,
&exception_state,
&bools[i]);
if (exception_state.is_exception_set()) {
return false;
}
}
}
impl->VariadicPrimitiveArguments(bools);
result_value.set(JS::UndefinedHandleValue);
return !exception_state.is_exception_set();
}
bool fcn_variadicStringArgumentsAfterOptionalArgument(
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)) {
NOTREACHED();
return false;
}
const JSClass* proto_class =
MozjsOperationsTestInterface::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<OperationsTestInterface>())) {
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);
OperationsTestInterface* impl =
wrapper_private->wrappable<OperationsTestInterface>().get();
// Optional arguments
TypeTraits<bool >::ConversionType optional_arg;
// Variadic argument
TypeTraits<std::vector<std::string> >::ConversionType strings;
size_t num_set_arguments = 0;
if (args.length() > 0) {
JS::RootedValue optional_value0(
context, args[0]);
FromJSValue(context,
optional_value0,
kNoConversionFlags,
&exception_state,
&optional_arg);
if (exception_state.is_exception_set()) {
return false;
}
++num_set_arguments;
}
// Get variadic arguments.
const size_t kLastOptionalArgIndex = 1;
if (num_set_arguments == kLastOptionalArgIndex) {
// If the last optional argument has been set, we will call the overload
// that takes the variadic argument, possibly with an empty vector in the
// case that there are no more arguments left.
++num_set_arguments;
}
const size_t kFirstVariadicArgIndex = 1;
if (args.length() > kFirstVariadicArgIndex) {
strings.resize(args.length() - kFirstVariadicArgIndex);
for (int i = 0; i + kFirstVariadicArgIndex < args.length(); ++i) {
JS::RootedValue variadic_argument_value(
context, args[i + kFirstVariadicArgIndex]);
FromJSValue(context,
variadic_argument_value,
kNoConversionFlags,
&exception_state,
&strings[i]);
if (exception_state.is_exception_set()) {
return false;
}
}
}
switch (num_set_arguments) {
case 0:
{
impl->VariadicStringArgumentsAfterOptionalArgument();
result_value.set(JS::UndefinedHandleValue);
return !exception_state.is_exception_set();
}
break;
case 2:
{
impl->VariadicStringArgumentsAfterOptionalArgument(optional_arg, strings);
result_value.set(JS::UndefinedHandleValue);
return !exception_state.is_exception_set();
}
break;
default:
NOTREACHED();
return false;
}
}
bool fcn_voidFunctionLongArg(
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)) {
NOTREACHED();
return false;
}
const JSClass* proto_class =
MozjsOperationsTestInterface::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<OperationsTestInterface>())) {
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);
OperationsTestInterface* impl =
wrapper_private->wrappable<OperationsTestInterface>().get();
const size_t kMinArguments = 1;
if (args.length() < kMinArguments) {
exception_state.SetSimpleException(script::kInvalidNumberOfArguments);
return false;
}
// Non-optional arguments
TypeTraits<int32_t >::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;
}
impl->VoidFunctionLongArg(arg);
result_value.set(JS::UndefinedHandleValue);
return !exception_state.is_exception_set();
}
bool fcn_voidFunctionNoArgs(
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)) {
NOTREACHED();
return false;
}
const JSClass* proto_class =
MozjsOperationsTestInterface::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<OperationsTestInterface>())) {
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);
OperationsTestInterface* impl =
wrapper_private->wrappable<OperationsTestInterface>().get();
impl->VoidFunctionNoArgs();
result_value.set(JS::UndefinedHandleValue);
return !exception_state.is_exception_set();
}
bool fcn_voidFunctionObjectArg(
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)) {
NOTREACHED();
return false;
}
const JSClass* proto_class =
MozjsOperationsTestInterface::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<OperationsTestInterface>())) {
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);
OperationsTestInterface* impl =
wrapper_private->wrappable<OperationsTestInterface>().get();
const size_t kMinArguments = 1;
if (args.length() < kMinArguments) {
exception_state.SetSimpleException(script::kInvalidNumberOfArguments);
return false;
}
// Non-optional arguments
TypeTraits<scoped_refptr<ArbitraryInterface> >::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;
}
impl->VoidFunctionObjectArg(arg);
result_value.set(JS::UndefinedHandleValue);
return !exception_state.is_exception_set();
}
bool fcn_voidFunctionStringArg(
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)) {
NOTREACHED();
return false;
}
const JSClass* proto_class =
MozjsOperationsTestInterface::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<OperationsTestInterface>())) {
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);
OperationsTestInterface* impl =
wrapper_private->wrappable<OperationsTestInterface>().get();
const size_t kMinArguments = 1;
if (args.length() < kMinArguments) {
exception_state.SetSimpleException(script::kInvalidNumberOfArguments);
return false;
}
// Non-optional arguments
TypeTraits<std::string >::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;
}
impl->VoidFunctionStringArg(arg);
result_value.set(JS::UndefinedHandleValue);
return !exception_state.is_exception_set();
}
bool staticfcn_overloadedFunction1(
JSContext* context, uint32_t argc, JS::Value *vp) {
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
MozjsExceptionState exception_state(context);
JS::RootedValue result_value(context);
const size_t kMinArguments = 1;
if (args.length() < kMinArguments) {
exception_state.SetSimpleException(script::kInvalidNumberOfArguments);
return false;
}
// Non-optional arguments
TypeTraits<double >::ConversionType arg;
DCHECK_LT(0, args.length());
JS::RootedValue non_optional_value0(
context, args[0]);
FromJSValue(context,
non_optional_value0,
(kConversionFlagRestricted),
&exception_state, &arg);
if (exception_state.is_exception_set()) {
return false;
}
OperationsTestInterface::OverloadedFunction(arg);
result_value.set(JS::UndefinedHandleValue);
return !exception_state.is_exception_set();
}
bool staticfcn_overloadedFunction2(
JSContext* context, uint32_t argc, JS::Value *vp) {
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
MozjsExceptionState exception_state(context);
JS::RootedValue result_value(context);
const size_t kMinArguments = 2;
if (args.length() < kMinArguments) {
exception_state.SetSimpleException(script::kInvalidNumberOfArguments);
return false;
}
// Non-optional arguments
TypeTraits<double >::ConversionType arg1;
TypeTraits<double >::ConversionType arg2;
DCHECK_LT(0, args.length());
JS::RootedValue non_optional_value0(
context, args[0]);
FromJSValue(context,
non_optional_value0,
(kConversionFlagRestricted),
&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,
(kConversionFlagRestricted),
&exception_state, &arg2);
if (exception_state.is_exception_set()) {
return false;
}
OperationsTestInterface::OverloadedFunction(arg1, arg2);
result_value.set(JS::UndefinedHandleValue);
return !exception_state.is_exception_set();
}
bool staticfcn_overloadedFunction(
JSContext* context, uint32_t argc, JS::Value *vp) {
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
switch(argc) {
case(1): {
// Overload resolution algorithm details found here:
// http://heycam.github.io/webidl/#dfn-overload-resolution-algorithm
if (true) {
return staticfcn_overloadedFunction1(
context, argc, vp);
}
break;
}
case(2): {
// Overload resolution algorithm details found here:
// http://heycam.github.io/webidl/#dfn-overload-resolution-algorithm
if (true) {
return staticfcn_overloadedFunction2(
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;
}
const JSPropertySpec prototype_properties[] = {
JS_PS_END
};
const JSFunctionSpec prototype_functions[] = {
JS_FNSPEC(
"longFunctionNoArgs", fcn_longFunctionNoArgs, NULL,
0, JSPROP_ENUMERATE, NULL),
JS_FNSPEC(
"objectFunctionNoArgs", fcn_objectFunctionNoArgs, NULL,
0, JSPROP_ENUMERATE, NULL),
JS_FNSPEC(
"optionalArgumentWithDefault", fcn_optionalArgumentWithDefault, NULL,
0, JSPROP_ENUMERATE, NULL),
JS_FNSPEC(
"optionalArguments", fcn_optionalArguments, NULL,
1, JSPROP_ENUMERATE, NULL),
JS_FNSPEC(
"optionalNullableArgumentsWithDefaults", fcn_optionalNullableArgumentsWithDefaults, NULL,
0, JSPROP_ENUMERATE, NULL),
JS_FNSPEC(
"overloadedFunction", fcn_overloadedFunction, NULL,
0, JSPROP_ENUMERATE, NULL),
JS_FNSPEC(
"overloadedNullable", fcn_overloadedNullable, NULL,
1, JSPROP_ENUMERATE, NULL),
JS_FNSPEC(
"stringFunctionNoArgs", fcn_stringFunctionNoArgs, NULL,
0, JSPROP_ENUMERATE, NULL),
JS_FNSPEC(
"variadicPrimitiveArguments", fcn_variadicPrimitiveArguments, NULL,
0, JSPROP_ENUMERATE, NULL),
JS_FNSPEC(
"variadicStringArgumentsAfterOptionalArgument", fcn_variadicStringArgumentsAfterOptionalArgument, NULL,
0, JSPROP_ENUMERATE, NULL),
JS_FNSPEC(
"voidFunctionLongArg", fcn_voidFunctionLongArg, NULL,
1, JSPROP_ENUMERATE, NULL),
JS_FNSPEC(
"voidFunctionNoArgs", fcn_voidFunctionNoArgs, NULL,
0, JSPROP_ENUMERATE, NULL),
JS_FNSPEC(
"voidFunctionObjectArg", fcn_voidFunctionObjectArg, NULL,
1, JSPROP_ENUMERATE, NULL),
JS_FNSPEC(
"voidFunctionStringArg", fcn_voidFunctionStringArg, NULL,
1, JSPROP_ENUMERATE, NULL),
JS_FS_END
};
const JSPropertySpec interface_object_properties[] = {
JS_PS_END
};
const JSFunctionSpec interface_object_functions[] = {
JS_FNSPEC(
"overloadedFunction", staticfcn_overloadedFunction, NULL,
1, JSPROP_ENUMERATE, NULL),
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);
interface_data->prototype = JS_NewObjectWithGivenProto(
context, &prototype_class_definition, parent_prototype
);
JS::RootedObject rooted_prototype(context, interface_data->prototype);
bool success = JS_DefineProperties(
context,
rooted_prototype,
prototype_properties);
DCHECK(success);
success = JS_DefineFunctions(
context, rooted_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_object_class_definition,
function_prototype);
// Add the InterfaceObject.name property.
JS::RootedObject rooted_interface_object(
context, interface_data->interface_object);
JS::RootedValue name_value(context);
const char name[] =
"OperationsTestInterface";
name_value.setString(JS_NewStringCopyZ(context, name));
success = JS_DefineProperty(
context, rooted_interface_object, "name", name_value, JSPROP_READONLY,
NULL, NULL);
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);
success = JS_LinkConstructorAndPrototype(
context,
rooted_interface_object,
rooted_prototype);
DCHECK(success);
}
inline InterfaceData* GetInterfaceData(JSContext* context) {
const int kInterfaceUniqueId = 39;
MozjsGlobalEnvironment* global_environment =
static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context));
// By convention, the |MozjsGlobalEnvironment| that we are associated with
// will hold our |InterfaceData| at index |kInterfaceUniqueId|, as we asked
// for it to be there in the first place, and could not have conflicted with
// any other interface.
return global_environment->GetInterfaceData(kInterfaceUniqueId);
}
} // namespace
// static
JSObject* MozjsOperationsTestInterface::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, &instance_class_definition, prototype));
DCHECK(new_object);
JS::RootedObject proxy(context,
ProxyHandler::NewProxy(
context, proxy_handler.Pointer(), new_object, prototype));
WrapperPrivate::AddPrivateData(context, proxy, wrappable);
return proxy;
}
// static
const JSClass* MozjsOperationsTestInterface::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));
const JSClass* proto_class = JS_GetClass(prototype);
return proto_class;
}
// static
JSObject* MozjsOperationsTestInterface::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* MozjsOperationsTestInterface::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