1 // Copyright 2014 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 // This file has been auto-generated by code_generator_v8.py. DO NOT MODIFY! 6 7 #include "config.h" 8 #include "V8TestInterfaceNamedConstructor.h" 9 10 #include "bindings/core/v8/ExceptionState.h" 11 #include "bindings/core/v8/V8DOMConfiguration.h" 12 #include "bindings/core/v8/V8HiddenValue.h" 13 #include "bindings/core/v8/V8ObjectConstructor.h" 14 #include "core/dom/ContextFeatures.h" 15 #include "core/dom/Document.h" 16 #include "core/frame/LocalDOMWindow.h" 17 #include "platform/RuntimeEnabledFeatures.h" 18 #include "platform/TraceEvent.h" 19 #include "wtf/GetPtr.h" 20 #include "wtf/RefPtr.h" 21 22 namespace blink { 23 24 const WrapperTypeInfo V8TestInterfaceNamedConstructor::wrapperTypeInfo = { gin::kEmbedderBlink, V8TestInterfaceNamedConstructor::domTemplate, V8TestInterfaceNamedConstructor::refObject, V8TestInterfaceNamedConstructor::derefObject, V8TestInterfaceNamedConstructor::createPersistentHandle, V8TestInterfaceNamedConstructor::toActiveDOMObject, 0, 0, V8TestInterfaceNamedConstructor::installConditionallyEnabledMethods, V8TestInterfaceNamedConstructor::installConditionallyEnabledProperties, 0, WrapperTypeInfo::WrapperTypeObjectPrototype, WrapperTypeInfo::ObjectClassId, WrapperTypeInfo::Dependent, WrapperTypeInfo::RefCountedObject }; 25 26 // This static member must be declared by DEFINE_WRAPPERTYPEINFO in TestInterfaceNamedConstructor.h. 27 // For details, see the comment of DEFINE_WRAPPERTYPEINFO in 28 // bindings/core/v8/ScriptWrappable.h. 29 const WrapperTypeInfo& TestInterfaceNamedConstructor::s_wrapperTypeInfo = V8TestInterfaceNamedConstructor::wrapperTypeInfo; 30 31 namespace TestInterfaceNamedConstructorV8Internal { 32 33 template <typename T> void V8_USE(T) { } 34 35 static void TestInterfaceNamedConstructorConstructorGetter(v8::Local<v8::String>, const v8::PropertyCallbackInfo<v8::Value>& info) 36 { 37 v8::Handle<v8::Value> data = info.Data(); 38 ASSERT(data->IsExternal()); 39 V8PerContextData* perContextData = V8PerContextData::from(info.Holder()->CreationContext()); 40 if (!perContextData) 41 return; 42 v8SetReturnValue(info, perContextData->constructorForType(WrapperTypeInfo::unwrap(data))); 43 } 44 45 static void TestInterfaceNamedConstructorForceSetAttributeOnThis(v8::Local<v8::String> name, v8::Local<v8::Value> v8Value, const v8::PropertyCallbackInfo<void>& info) 46 { 47 if (info.This()->IsObject()) 48 v8::Handle<v8::Object>::Cast(info.This())->ForceSet(name, v8Value); 49 } 50 51 static void TestInterfaceNamedConstructorForceSetAttributeOnThisCallback(v8::Local<v8::String> name, v8::Local<v8::Value> v8Value, const v8::PropertyCallbackInfo<void>& info) 52 { 53 TestInterfaceNamedConstructorV8Internal::TestInterfaceNamedConstructorForceSetAttributeOnThis(name, v8Value, info); 54 } 55 56 } // namespace TestInterfaceNamedConstructorV8Internal 57 58 static const V8DOMConfiguration::AttributeConfiguration V8TestInterfaceNamedConstructorAttributes[] = { 59 {"testNamedConstructorConstructorAttribute", TestInterfaceNamedConstructorV8Internal::TestInterfaceNamedConstructorConstructorGetter, TestInterfaceNamedConstructorV8Internal::TestInterfaceNamedConstructorForceSetAttributeOnThisCallback, 0, 0, const_cast<WrapperTypeInfo*>(&V8TestNamedConstructor::wrapperTypeInfo), static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::DontEnum), V8DOMConfiguration::ExposedToAllScripts, V8DOMConfiguration::OnInstance}, 60 }; 61 62 const WrapperTypeInfo V8TestInterfaceNamedConstructorConstructor::wrapperTypeInfo = { gin::kEmbedderBlink, V8TestInterfaceNamedConstructorConstructor::domTemplate, V8TestInterfaceNamedConstructor::refObject, V8TestInterfaceNamedConstructor::derefObject, V8TestInterfaceNamedConstructor::createPersistentHandle, V8TestInterfaceNamedConstructor::toActiveDOMObject, 0, 0, V8TestInterfaceNamedConstructor::installConditionallyEnabledMethods, V8TestInterfaceNamedConstructor::installConditionallyEnabledProperties, 0, WrapperTypeInfo::WrapperTypeObjectPrototype, WrapperTypeInfo::ObjectClassId, WrapperTypeInfo::Dependent, WrapperTypeInfo::RefCountedObject }; 63 64 static void V8TestInterfaceNamedConstructorConstructorCallback(const v8::FunctionCallbackInfo<v8::Value>& info) 65 { 66 if (!info.IsConstructCall()) { 67 V8ThrowException::throwTypeError(ExceptionMessages::constructorNotCallableAsFunction("Audio"), info.GetIsolate()); 68 return; 69 } 70 71 if (ConstructorMode::current(info.GetIsolate()) == ConstructorMode::WrapExistingObject) { 72 v8SetReturnValue(info, info.Holder()); 73 return; 74 } 75 ExceptionState exceptionState(ExceptionState::ConstructionContext, "TestInterfaceNamedConstructor", info.Holder(), info.GetIsolate()); 76 if (UNLIKELY(info.Length() < 1)) { 77 setMinimumArityTypeError(exceptionState, 1, info.Length()); 78 exceptionState.throwIfNeeded(); 79 return; 80 } 81 V8StringResource<> stringArg; 82 bool defaultUndefinedOptionalBooleanArg; 83 int defaultUndefinedOptionalLongArg; 84 V8StringResource<> defaultUndefinedOptionalStringArg; 85 V8StringResource<> defaultNullStringOptionalstringArg; 86 V8StringResource<> optionalStringArg; 87 { 88 TOSTRING_VOID_INTERNAL(stringArg, info[0]); 89 defaultUndefinedOptionalBooleanArg = info[1]->BooleanValue(); 90 TONATIVE_VOID_EXCEPTIONSTATE_INTERNAL(defaultUndefinedOptionalLongArg, toInt32(info[2], exceptionState), exceptionState); 91 TOSTRING_VOID_INTERNAL(defaultUndefinedOptionalStringArg, info[3]); 92 if (!info[4]->IsUndefined()) { 93 TOSTRING_VOID_INTERNAL(defaultNullStringOptionalstringArg, info[4]); 94 } else { 95 defaultNullStringOptionalstringArg = nullptr; 96 } 97 if (UNLIKELY(info.Length() <= 5)) { 98 Document& document = *toDocument(currentExecutionContext(info.GetIsolate())); 99 RefPtr<TestInterfaceNamedConstructor> impl = TestInterfaceNamedConstructor::createForJSConstructor(document, stringArg, defaultUndefinedOptionalBooleanArg, defaultUndefinedOptionalLongArg, defaultUndefinedOptionalStringArg, defaultNullStringOptionalstringArg, exceptionState); 100 if (exceptionState.hadException()) { 101 exceptionState.throwIfNeeded(); 102 return; 103 } 104 v8::Handle<v8::Object> wrapper = info.Holder(); 105 impl->associateWithWrapper(&V8TestInterfaceNamedConstructorConstructor::wrapperTypeInfo, wrapper, info.GetIsolate()); 106 v8SetReturnValue(info, wrapper); 107 return; 108 } 109 TOSTRING_VOID_INTERNAL(optionalStringArg, info[5]); 110 } 111 Document& document = *toDocument(currentExecutionContext(info.GetIsolate())); 112 RefPtr<TestInterfaceNamedConstructor> impl = TestInterfaceNamedConstructor::createForJSConstructor(document, stringArg, defaultUndefinedOptionalBooleanArg, defaultUndefinedOptionalLongArg, defaultUndefinedOptionalStringArg, defaultNullStringOptionalstringArg, optionalStringArg, exceptionState); 113 if (exceptionState.hadException()) { 114 exceptionState.throwIfNeeded(); 115 return; 116 } 117 v8::Handle<v8::Object> wrapper = info.Holder(); 118 impl->associateWithWrapper(&V8TestInterfaceNamedConstructorConstructor::wrapperTypeInfo, wrapper, info.GetIsolate()); 119 v8SetReturnValue(info, wrapper); 120 } 121 122 v8::Handle<v8::FunctionTemplate> V8TestInterfaceNamedConstructorConstructor::domTemplate(v8::Isolate* isolate) 123 { 124 static int domTemplateKey; // This address is used for a key to look up the dom template. 125 V8PerIsolateData* data = V8PerIsolateData::from(isolate); 126 v8::Local<v8::FunctionTemplate> result = data->existingDOMTemplate(&domTemplateKey); 127 if (!result.IsEmpty()) 128 return result; 129 130 TRACE_EVENT_SCOPED_SAMPLING_STATE("blink", "BuildDOMTemplate"); 131 result = v8::FunctionTemplate::New(isolate, V8TestInterfaceNamedConstructorConstructorCallback); 132 v8::Local<v8::ObjectTemplate> instanceTemplate = result->InstanceTemplate(); 133 instanceTemplate->SetInternalFieldCount(V8TestInterfaceNamedConstructor::internalFieldCount); 134 result->SetClassName(v8AtomicString(isolate, "TestInterfaceNamedConstructor")); 135 result->Inherit(V8TestInterfaceNamedConstructor::domTemplate(isolate)); 136 data->setDOMTemplate(&domTemplateKey, result); 137 return result; 138 } 139 140 static void installV8TestInterfaceNamedConstructorTemplate(v8::Handle<v8::FunctionTemplate> functionTemplate, v8::Isolate* isolate) 141 { 142 functionTemplate->ReadOnlyPrototype(); 143 144 v8::Local<v8::Signature> defaultSignature; 145 defaultSignature = V8DOMConfiguration::installDOMClassTemplate(functionTemplate, "TestInterfaceNamedConstructor", v8::Local<v8::FunctionTemplate>(), V8TestInterfaceNamedConstructor::internalFieldCount, 146 V8TestInterfaceNamedConstructorAttributes, WTF_ARRAY_LENGTH(V8TestInterfaceNamedConstructorAttributes), 147 0, 0, 148 0, 0, 149 isolate); 150 v8::Local<v8::ObjectTemplate> instanceTemplate ALLOW_UNUSED = functionTemplate->InstanceTemplate(); 151 v8::Local<v8::ObjectTemplate> prototypeTemplate ALLOW_UNUSED = functionTemplate->PrototypeTemplate(); 152 153 // Custom toString template 154 functionTemplate->Set(v8AtomicString(isolate, "toString"), V8PerIsolateData::from(isolate)->toStringTemplate()); 155 } 156 157 v8::Handle<v8::FunctionTemplate> V8TestInterfaceNamedConstructor::domTemplate(v8::Isolate* isolate) 158 { 159 return V8DOMConfiguration::domClassTemplate(isolate, const_cast<WrapperTypeInfo*>(&wrapperTypeInfo), installV8TestInterfaceNamedConstructorTemplate); 160 } 161 162 bool V8TestInterfaceNamedConstructor::hasInstance(v8::Handle<v8::Value> v8Value, v8::Isolate* isolate) 163 { 164 return V8PerIsolateData::from(isolate)->hasInstance(&wrapperTypeInfo, v8Value); 165 } 166 167 v8::Handle<v8::Object> V8TestInterfaceNamedConstructor::findInstanceInPrototypeChain(v8::Handle<v8::Value> v8Value, v8::Isolate* isolate) 168 { 169 return V8PerIsolateData::from(isolate)->findInstanceInPrototypeChain(&wrapperTypeInfo, v8Value); 170 } 171 172 TestInterfaceNamedConstructor* V8TestInterfaceNamedConstructor::toImplWithTypeCheck(v8::Isolate* isolate, v8::Handle<v8::Value> value) 173 { 174 return hasInstance(value, isolate) ? blink::toScriptWrappableBase(v8::Handle<v8::Object>::Cast(value))->toImpl<TestInterfaceNamedConstructor>() : 0; 175 } 176 177 ActiveDOMObject* V8TestInterfaceNamedConstructor::toActiveDOMObject(v8::Handle<v8::Object> wrapper) 178 { 179 return toImpl(wrapper); 180 } 181 182 183 void V8TestInterfaceNamedConstructor::refObject(ScriptWrappableBase* internalPointer) 184 { 185 internalPointer->toImpl<TestInterfaceNamedConstructor>()->ref(); 186 } 187 188 void V8TestInterfaceNamedConstructor::derefObject(ScriptWrappableBase* internalPointer) 189 { 190 internalPointer->toImpl<TestInterfaceNamedConstructor>()->deref(); 191 } 192 193 WrapperPersistentNode* V8TestInterfaceNamedConstructor::createPersistentHandle(ScriptWrappableBase* internalPointer) 194 { 195 ASSERT_NOT_REACHED(); 196 return 0; 197 } 198 199 template<> 200 v8::Handle<v8::Value> toV8NoInline(TestInterfaceNamedConstructor* impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate) 201 { 202 return toV8(impl, creationContext, isolate); 203 } 204 205 } // namespace blink 206