Home | History | Annotate | Download | only in results
      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/v8/ExceptionState.h"
     11 #include "bindings/v8/V8DOMConfiguration.h"
     12 #include "bindings/v8/V8HiddenValue.h"
     13 #include "bindings/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 WebCore {
     23 
     24 static void initializeScriptWrappableForInterface(TestInterfaceNamedConstructor* object)
     25 {
     26     if (ScriptWrappable::wrapperCanBeStoredInObject(object))
     27         ScriptWrappable::fromObject(object)->setTypeInfo(&V8TestInterfaceNamedConstructor::wrapperTypeInfo);
     28     else
     29         ASSERT_NOT_REACHED();
     30 }
     31 
     32 } // namespace WebCore
     33 
     34 void webCoreInitializeScriptWrappableForInterface(WebCore::TestInterfaceNamedConstructor* object)
     35 {
     36     WebCore::initializeScriptWrappableForInterface(object);
     37 }
     38 
     39 namespace WebCore {
     40 const WrapperTypeInfo V8TestInterfaceNamedConstructor::wrapperTypeInfo = { gin::kEmbedderBlink, V8TestInterfaceNamedConstructor::domTemplate, V8TestInterfaceNamedConstructor::derefObject, V8TestInterfaceNamedConstructor::toActiveDOMObject, 0, 0, V8TestInterfaceNamedConstructor::installPerContextEnabledMethods, 0, WrapperTypeObjectPrototype, RefCountedObject };
     41 
     42 namespace TestInterfaceNamedConstructorV8Internal {
     43 
     44 template <typename T> void V8_USE(T) { }
     45 
     46 static void TestInterfaceNamedConstructorConstructorGetter(v8::Local<v8::String>, const v8::PropertyCallbackInfo<v8::Value>& info)
     47 {
     48     v8::Handle<v8::Value> data = info.Data();
     49     ASSERT(data->IsExternal());
     50     V8PerContextData* perContextData = V8PerContextData::from(info.Holder()->CreationContext());
     51     if (!perContextData)
     52         return;
     53     v8SetReturnValue(info, perContextData->constructorForType(WrapperTypeInfo::unwrap(data)));
     54 }
     55 
     56 static void TestInterfaceNamedConstructorReplaceableAttributeSetter(v8::Local<v8::String> name, v8::Local<v8::Value> v8Value, const v8::PropertyCallbackInfo<void>& info)
     57 {
     58     if (info.This()->IsObject())
     59         v8::Handle<v8::Object>::Cast(info.This())->ForceSet(name, v8Value);
     60 }
     61 
     62 static void TestInterfaceNamedConstructorReplaceableAttributeSetterCallback(v8::Local<v8::String> name, v8::Local<v8::Value> v8Value, const v8::PropertyCallbackInfo<void>& info)
     63 {
     64     TestInterfaceNamedConstructorV8Internal::TestInterfaceNamedConstructorReplaceableAttributeSetter(name, v8Value, info);
     65 }
     66 
     67 } // namespace TestInterfaceNamedConstructorV8Internal
     68 
     69 static const V8DOMConfiguration::AttributeConfiguration V8TestInterfaceNamedConstructorAttributes[] = {
     70     {"testNamedConstructorConstructorAttribute", TestInterfaceNamedConstructorV8Internal::TestInterfaceNamedConstructorConstructorGetter, TestInterfaceNamedConstructorV8Internal::TestInterfaceNamedConstructorReplaceableAttributeSetterCallback, 0, 0, const_cast<WrapperTypeInfo*>(&V8TestNamedConstructor::wrapperTypeInfo), static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::DontEnum), 0 /* on instance */},
     71 };
     72 
     73 const WrapperTypeInfo V8TestInterfaceNamedConstructorConstructor::wrapperTypeInfo = { gin::kEmbedderBlink, V8TestInterfaceNamedConstructorConstructor::domTemplate, V8TestInterfaceNamedConstructor::derefObject, V8TestInterfaceNamedConstructor::toActiveDOMObject, 0, 0, V8TestInterfaceNamedConstructor::installPerContextEnabledMethods, 0, WrapperTypeObjectPrototype, RefCountedObject };
     74 
     75 static void V8TestInterfaceNamedConstructorConstructorCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
     76 {
     77     v8::Isolate* isolate = info.GetIsolate();
     78     if (!info.IsConstructCall()) {
     79         throwTypeError(ExceptionMessages::constructorNotCallableAsFunction("Audio"), isolate);
     80         return;
     81     }
     82 
     83     if (ConstructorMode::current(isolate) == ConstructorMode::WrapExistingObject) {
     84         v8SetReturnValue(info, info.Holder());
     85         return;
     86     }
     87 
     88     Document* documentPtr = currentDOMWindow(isolate)->document();
     89     ASSERT(documentPtr);
     90     Document& document = *documentPtr;
     91 
     92     // Make sure the document is added to the DOM Node map. Otherwise, the TestInterfaceNamedConstructor instance
     93     // may end up being the only node in the map and get garbage-collected prematurely.
     94     toV8(documentPtr, info.Holder(), isolate);
     95 
     96     ExceptionState exceptionState(ExceptionState::ConstructionContext, "TestInterfaceNamedConstructor", info.Holder(), isolate);
     97     if (UNLIKELY(info.Length() < 1)) {
     98         throwMinimumArityTypeError(exceptionState, 1, info.Length());
     99         return;
    100     }
    101     V8StringResource<> stringArg;
    102     bool defaultUndefinedOptionalBooleanArg;
    103     int defaultUndefinedOptionalLongArg;
    104     V8StringResource<> defaultUndefinedOptionalStringArg;
    105     V8StringResource<> defaultNullStringOptionalstringArg;
    106     V8StringResource<> optionalStringArg;
    107     {
    108         v8::TryCatch block;
    109         V8RethrowTryCatchScope rethrow(block);
    110         TOSTRING_VOID_INTERNAL(stringArg, info[0]);
    111         TONATIVE_VOID_INTERNAL(defaultUndefinedOptionalBooleanArg, info[1]->BooleanValue());
    112         TONATIVE_VOID_EXCEPTIONSTATE_INTERNAL(defaultUndefinedOptionalLongArg, toInt32(info[2], exceptionState), exceptionState);
    113         TOSTRING_VOID_INTERNAL(defaultUndefinedOptionalStringArg, info[3]);
    114         TOSTRING_VOID_INTERNAL(defaultNullStringOptionalstringArg, argumentOrNull(info, 4));
    115         if (UNLIKELY(info.Length() <= 5)) {
    116             RefPtr<TestInterfaceNamedConstructor> impl = TestInterfaceNamedConstructor::createForJSConstructor(document, stringArg, defaultUndefinedOptionalBooleanArg, defaultUndefinedOptionalLongArg, defaultUndefinedOptionalStringArg, defaultNullStringOptionalstringArg, exceptionState);
    117             v8::Handle<v8::Object> wrapper = info.Holder();
    118             V8DOMWrapper::associateObjectWithWrapper<V8TestInterfaceNamedConstructor>(impl.release(), &V8TestInterfaceNamedConstructorConstructor::wrapperTypeInfo, wrapper, isolate, WrapperConfiguration::Dependent);
    119             v8SetReturnValue(info, wrapper);
    120             return;
    121         }
    122         TOSTRING_VOID_INTERNAL(optionalStringArg, info[5]);
    123     }
    124     RefPtr<TestInterfaceNamedConstructor> impl = TestInterfaceNamedConstructor::createForJSConstructor(document, stringArg, defaultUndefinedOptionalBooleanArg, defaultUndefinedOptionalLongArg, defaultUndefinedOptionalStringArg, defaultNullStringOptionalstringArg, optionalStringArg, exceptionState);
    125     if (exceptionState.throwIfNeeded())
    126         return;
    127 
    128     v8::Handle<v8::Object> wrapper = info.Holder();
    129     V8DOMWrapper::associateObjectWithWrapper<V8TestInterfaceNamedConstructor>(impl.release(), &V8TestInterfaceNamedConstructorConstructor::wrapperTypeInfo, wrapper, isolate, WrapperConfiguration::Dependent);
    130     v8SetReturnValue(info, wrapper);
    131 }
    132 
    133 v8::Handle<v8::FunctionTemplate> V8TestInterfaceNamedConstructorConstructor::domTemplate(v8::Isolate* isolate)
    134 {
    135     static int domTemplateKey; // This address is used for a key to look up the dom template.
    136     V8PerIsolateData* data = V8PerIsolateData::from(isolate);
    137     v8::Local<v8::FunctionTemplate> result = data->existingDOMTemplate(&domTemplateKey);
    138     if (!result.IsEmpty())
    139         return result;
    140 
    141     TRACE_EVENT_SCOPED_SAMPLING_STATE("Blink", "BuildDOMTemplate");
    142     result = v8::FunctionTemplate::New(isolate, V8TestInterfaceNamedConstructorConstructorCallback);
    143     v8::Local<v8::ObjectTemplate> instanceTemplate = result->InstanceTemplate();
    144     instanceTemplate->SetInternalFieldCount(V8TestInterfaceNamedConstructor::internalFieldCount);
    145     result->SetClassName(v8AtomicString(isolate, "TestInterfaceNamedConstructor"));
    146     result->Inherit(V8TestInterfaceNamedConstructor::domTemplate(isolate));
    147     data->setDOMTemplate(&domTemplateKey, result);
    148     return result;
    149 }
    150 
    151 static void configureV8TestInterfaceNamedConstructorTemplate(v8::Handle<v8::FunctionTemplate> functionTemplate, v8::Isolate* isolate)
    152 {
    153     functionTemplate->ReadOnlyPrototype();
    154 
    155     v8::Local<v8::Signature> defaultSignature;
    156     defaultSignature = V8DOMConfiguration::installDOMClassTemplate(functionTemplate, "TestInterfaceNamedConstructor", v8::Local<v8::FunctionTemplate>(), V8TestInterfaceNamedConstructor::internalFieldCount,
    157         V8TestInterfaceNamedConstructorAttributes, WTF_ARRAY_LENGTH(V8TestInterfaceNamedConstructorAttributes),
    158         0, 0,
    159         0, 0,
    160         isolate);
    161     v8::Local<v8::ObjectTemplate> instanceTemplate ALLOW_UNUSED = functionTemplate->InstanceTemplate();
    162     v8::Local<v8::ObjectTemplate> prototypeTemplate ALLOW_UNUSED = functionTemplate->PrototypeTemplate();
    163 
    164     // Custom toString template
    165     functionTemplate->Set(v8AtomicString(isolate, "toString"), V8PerIsolateData::from(isolate)->toStringTemplate());
    166 }
    167 
    168 v8::Handle<v8::FunctionTemplate> V8TestInterfaceNamedConstructor::domTemplate(v8::Isolate* isolate)
    169 {
    170     return V8DOMConfiguration::domClassTemplate(isolate, const_cast<WrapperTypeInfo*>(&wrapperTypeInfo), configureV8TestInterfaceNamedConstructorTemplate);
    171 }
    172 
    173 bool V8TestInterfaceNamedConstructor::hasInstance(v8::Handle<v8::Value> v8Value, v8::Isolate* isolate)
    174 {
    175     return V8PerIsolateData::from(isolate)->hasInstance(&wrapperTypeInfo, v8Value);
    176 }
    177 
    178 v8::Handle<v8::Object> V8TestInterfaceNamedConstructor::findInstanceInPrototypeChain(v8::Handle<v8::Value> v8Value, v8::Isolate* isolate)
    179 {
    180     return V8PerIsolateData::from(isolate)->findInstanceInPrototypeChain(&wrapperTypeInfo, v8Value);
    181 }
    182 
    183 TestInterfaceNamedConstructor* V8TestInterfaceNamedConstructor::toNativeWithTypeCheck(v8::Isolate* isolate, v8::Handle<v8::Value> value)
    184 {
    185     return hasInstance(value, isolate) ? fromInternalPointer(v8::Handle<v8::Object>::Cast(value)->GetAlignedPointerFromInternalField(v8DOMWrapperObjectIndex)) : 0;
    186 }
    187 
    188 ActiveDOMObject* V8TestInterfaceNamedConstructor::toActiveDOMObject(v8::Handle<v8::Object> wrapper)
    189 {
    190     return toNative(wrapper);
    191 }
    192 
    193 v8::Handle<v8::Object> wrap(TestInterfaceNamedConstructor* impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
    194 {
    195     ASSERT(impl);
    196     ASSERT(!DOMDataStore::containsWrapper<V8TestInterfaceNamedConstructor>(impl, isolate));
    197     return V8TestInterfaceNamedConstructor::createWrapper(impl, creationContext, isolate);
    198 }
    199 
    200 v8::Handle<v8::Object> V8TestInterfaceNamedConstructor::createWrapper(PassRefPtr<TestInterfaceNamedConstructor> impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
    201 {
    202     ASSERT(impl);
    203     ASSERT(!DOMDataStore::containsWrapper<V8TestInterfaceNamedConstructor>(impl.get(), isolate));
    204     if (ScriptWrappable::wrapperCanBeStoredInObject(impl.get())) {
    205         const WrapperTypeInfo* actualInfo = ScriptWrappable::fromObject(impl.get())->typeInfo();
    206         // Might be a XXXConstructor::wrapperTypeInfo instead of an XXX::wrapperTypeInfo. These will both have
    207         // the same object de-ref functions, though, so use that as the basis of the check.
    208         RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(actualInfo->derefObjectFunction == wrapperTypeInfo.derefObjectFunction);
    209     }
    210 
    211     v8::Handle<v8::Object> wrapper = V8DOMWrapper::createWrapper(creationContext, &wrapperTypeInfo, toInternalPointer(impl.get()), isolate);
    212     if (UNLIKELY(wrapper.IsEmpty()))
    213         return wrapper;
    214 
    215     installPerContextEnabledProperties(wrapper, impl.get(), isolate);
    216     V8DOMWrapper::associateObjectWithWrapper<V8TestInterfaceNamedConstructor>(impl, &wrapperTypeInfo, wrapper, isolate, WrapperConfiguration::Dependent);
    217     return wrapper;
    218 }
    219 
    220 void V8TestInterfaceNamedConstructor::derefObject(void* object)
    221 {
    222     fromInternalPointer(object)->deref();
    223 }
    224 
    225 template<>
    226 v8::Handle<v8::Value> toV8NoInline(TestInterfaceNamedConstructor* impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
    227 {
    228     return toV8(impl, creationContext, isolate);
    229 }
    230 
    231 } // namespace WebCore
    232