Home | History | Annotate | Download | only in core
      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 "V8TestInterfaceConstructor.h"
      9 
     10 #include "bindings/core/v8/Dictionary.h"
     11 #include "bindings/core/v8/ExceptionState.h"
     12 #include "bindings/core/v8/V8DOMConfiguration.h"
     13 #include "bindings/core/v8/V8HiddenValue.h"
     14 #include "bindings/core/v8/V8ObjectConstructor.h"
     15 #include "bindings/core/v8/V8TestInterfaceEmpty.h"
     16 #include "core/dom/ContextFeatures.h"
     17 #include "core/dom/Document.h"
     18 #include "core/frame/LocalDOMWindow.h"
     19 #include "core/frame/UseCounter.h"
     20 #include "platform/RuntimeEnabledFeatures.h"
     21 #include "platform/TraceEvent.h"
     22 #include "wtf/GetPtr.h"
     23 #include "wtf/RefPtr.h"
     24 
     25 namespace blink {
     26 
     27 const WrapperTypeInfo V8TestInterfaceConstructor::wrapperTypeInfo = { gin::kEmbedderBlink, V8TestInterfaceConstructor::domTemplate, V8TestInterfaceConstructor::refObject, V8TestInterfaceConstructor::derefObject, V8TestInterfaceConstructor::createPersistentHandle, 0, 0, 0, V8TestInterfaceConstructor::installConditionallyEnabledMethods, V8TestInterfaceConstructor::installConditionallyEnabledProperties, 0, WrapperTypeInfo::WrapperTypeObjectPrototype, WrapperTypeInfo::ObjectClassId, WrapperTypeInfo::Independent, WrapperTypeInfo::RefCountedObject };
     28 
     29 // This static member must be declared by DEFINE_WRAPPERTYPEINFO in TestInterfaceConstructor.h.
     30 // For details, see the comment of DEFINE_WRAPPERTYPEINFO in
     31 // bindings/core/v8/ScriptWrappable.h.
     32 const WrapperTypeInfo& TestInterfaceConstructor::s_wrapperTypeInfo = V8TestInterfaceConstructor::wrapperTypeInfo;
     33 
     34 namespace TestInterfaceConstructorV8Internal {
     35 
     36 template <typename T> void V8_USE(T) { }
     37 
     38 static void constructor1(const v8::FunctionCallbackInfo<v8::Value>& info)
     39 {
     40     ExceptionState exceptionState(ExceptionState::ConstructionContext, "TestInterfaceConstructor", info.Holder(), info.GetIsolate());
     41     ExecutionContext* executionContext = currentExecutionContext(info.GetIsolate());
     42     Document& document = *toDocument(currentExecutionContext(info.GetIsolate()));
     43     RefPtr<TestInterfaceConstructor> impl = TestInterfaceConstructor::create(executionContext, document, exceptionState);
     44     if (exceptionState.hadException()) {
     45         exceptionState.throwIfNeeded();
     46         return;
     47     }
     48     v8::Handle<v8::Object> wrapper = info.Holder();
     49     impl->associateWithWrapper(&V8TestInterfaceConstructor::wrapperTypeInfo, wrapper, info.GetIsolate());
     50     v8SetReturnValue(info, wrapper);
     51 }
     52 
     53 static void constructor2(const v8::FunctionCallbackInfo<v8::Value>& info)
     54 {
     55     ExceptionState exceptionState(ExceptionState::ConstructionContext, "TestInterfaceConstructor", info.Holder(), info.GetIsolate());
     56     double doubleArg;
     57     V8StringResource<> stringArg;
     58     TestInterfaceEmpty* testInterfaceEmptyArg;
     59     Dictionary dictionaryArg;
     60     Vector<String> sequenceStringArg;
     61     Vector<Dictionary> sequenceDictionaryArg;
     62     Dictionary optionalDictionaryArg;
     63     TestInterfaceEmpty* optionalTestInterfaceEmptyArg;
     64     {
     65         TONATIVE_VOID_EXCEPTIONSTATE_INTERNAL(doubleArg, toDouble(info[0], exceptionState), exceptionState);
     66         TOSTRING_VOID_INTERNAL(stringArg, info[1]);
     67         testInterfaceEmptyArg = V8TestInterfaceEmpty::toImplWithTypeCheck(info.GetIsolate(), info[2]);
     68         if (!isUndefinedOrNull(info[3]) && !info[3]->IsObject()) {
     69             exceptionState.throwTypeError("parameter 4 ('dictionaryArg') is not an object.");
     70             exceptionState.throwIfNeeded();
     71             return;
     72         }
     73         dictionaryArg = Dictionary(info[3], info.GetIsolate());
     74         TONATIVE_VOID_EXCEPTIONSTATE_INTERNAL(sequenceStringArg, toImplArray<String>(info[4], 5, info.GetIsolate(), exceptionState), exceptionState);
     75         TONATIVE_VOID_EXCEPTIONSTATE_INTERNAL(sequenceDictionaryArg, toImplArray<Dictionary>(info[5], 6, info.GetIsolate(), exceptionState), exceptionState);
     76         if (!isUndefinedOrNull(info[6]) && !info[6]->IsObject()) {
     77             exceptionState.throwTypeError("parameter 7 ('optionalDictionaryArg') is not an object.");
     78             exceptionState.throwIfNeeded();
     79             return;
     80         }
     81         optionalDictionaryArg = Dictionary(info[6], info.GetIsolate());
     82         optionalTestInterfaceEmptyArg = V8TestInterfaceEmpty::toImplWithTypeCheck(info.GetIsolate(), info[7]);
     83     }
     84     ExecutionContext* executionContext = currentExecutionContext(info.GetIsolate());
     85     Document& document = *toDocument(currentExecutionContext(info.GetIsolate()));
     86     RefPtr<TestInterfaceConstructor> impl = TestInterfaceConstructor::create(executionContext, document, doubleArg, stringArg, testInterfaceEmptyArg, dictionaryArg, sequenceStringArg, sequenceDictionaryArg, optionalDictionaryArg, optionalTestInterfaceEmptyArg, exceptionState);
     87     if (exceptionState.hadException()) {
     88         exceptionState.throwIfNeeded();
     89         return;
     90     }
     91     v8::Handle<v8::Object> wrapper = info.Holder();
     92     impl->associateWithWrapper(&V8TestInterfaceConstructor::wrapperTypeInfo, wrapper, info.GetIsolate());
     93     v8SetReturnValue(info, wrapper);
     94 }
     95 
     96 static void constructor3(const v8::FunctionCallbackInfo<v8::Value>& info)
     97 {
     98     ExceptionState exceptionState(ExceptionState::ConstructionContext, "TestInterfaceConstructor", info.Holder(), info.GetIsolate());
     99     V8StringResource<> arg;
    100     V8StringResource<> optArg;
    101     {
    102         TOSTRING_VOID_INTERNAL(arg, info[0]);
    103         if (UNLIKELY(info.Length() <= 1)) {
    104             ExecutionContext* executionContext = currentExecutionContext(info.GetIsolate());
    105             Document& document = *toDocument(currentExecutionContext(info.GetIsolate()));
    106             RefPtr<TestInterfaceConstructor> impl = TestInterfaceConstructor::create(executionContext, document, arg, exceptionState);
    107             if (exceptionState.hadException()) {
    108                 exceptionState.throwIfNeeded();
    109                 return;
    110             }
    111             v8::Handle<v8::Object> wrapper = info.Holder();
    112             impl->associateWithWrapper(&V8TestInterfaceConstructor::wrapperTypeInfo, wrapper, info.GetIsolate());
    113             v8SetReturnValue(info, wrapper);
    114             return;
    115         }
    116         TOSTRING_VOID_INTERNAL(optArg, info[1]);
    117     }
    118     ExecutionContext* executionContext = currentExecutionContext(info.GetIsolate());
    119     Document& document = *toDocument(currentExecutionContext(info.GetIsolate()));
    120     RefPtr<TestInterfaceConstructor> impl = TestInterfaceConstructor::create(executionContext, document, arg, optArg, exceptionState);
    121     if (exceptionState.hadException()) {
    122         exceptionState.throwIfNeeded();
    123         return;
    124     }
    125     v8::Handle<v8::Object> wrapper = info.Holder();
    126     impl->associateWithWrapper(&V8TestInterfaceConstructor::wrapperTypeInfo, wrapper, info.GetIsolate());
    127     v8SetReturnValue(info, wrapper);
    128 }
    129 
    130 static void constructor4(const v8::FunctionCallbackInfo<v8::Value>& info)
    131 {
    132     ExceptionState exceptionState(ExceptionState::ConstructionContext, "TestInterfaceConstructor", info.Holder(), info.GetIsolate());
    133     V8StringResource<> arg;
    134     V8StringResource<> arg2;
    135     V8StringResource<> arg3;
    136     {
    137         TOSTRING_VOID_INTERNAL(arg, info[0]);
    138         TOSTRING_VOID_INTERNAL(arg2, info[1]);
    139         TOSTRING_VOID_INTERNAL(arg3, info[2]);
    140     }
    141     ExecutionContext* executionContext = currentExecutionContext(info.GetIsolate());
    142     Document& document = *toDocument(currentExecutionContext(info.GetIsolate()));
    143     RefPtr<TestInterfaceConstructor> impl = TestInterfaceConstructor::create(executionContext, document, arg, arg2, arg3, exceptionState);
    144     if (exceptionState.hadException()) {
    145         exceptionState.throwIfNeeded();
    146         return;
    147     }
    148     v8::Handle<v8::Object> wrapper = info.Holder();
    149     impl->associateWithWrapper(&V8TestInterfaceConstructor::wrapperTypeInfo, wrapper, info.GetIsolate());
    150     v8SetReturnValue(info, wrapper);
    151 }
    152 
    153 static void constructor(const v8::FunctionCallbackInfo<v8::Value>& info)
    154 {
    155     ExceptionState exceptionState(ExceptionState::ConstructionContext, "TestInterfaceConstructor", info.Holder(), info.GetIsolate());
    156     switch (std::min(8, info.Length())) {
    157     case 0:
    158         if (true) {
    159             TestInterfaceConstructorV8Internal::constructor1(info);
    160             return;
    161         }
    162         break;
    163     case 1:
    164         if (true) {
    165             TestInterfaceConstructorV8Internal::constructor3(info);
    166             return;
    167         }
    168         break;
    169     case 2:
    170         if (true) {
    171             TestInterfaceConstructorV8Internal::constructor3(info);
    172             return;
    173         }
    174         break;
    175     case 3:
    176         if (true) {
    177             TestInterfaceConstructorV8Internal::constructor4(info);
    178             return;
    179         }
    180         break;
    181     case 6:
    182         if (true) {
    183             TestInterfaceConstructorV8Internal::constructor2(info);
    184             return;
    185         }
    186         break;
    187     case 7:
    188         if (true) {
    189             TestInterfaceConstructorV8Internal::constructor2(info);
    190             return;
    191         }
    192         break;
    193     case 8:
    194         if (true) {
    195             TestInterfaceConstructorV8Internal::constructor2(info);
    196             return;
    197         }
    198         break;
    199     default:
    200         if (info.Length() >= 0) {
    201             throwArityTypeError(exceptionState, "[0, 1, 2, 3, 6, 7, 8]", info.Length());
    202             return;
    203         }
    204         exceptionState.throwTypeError(ExceptionMessages::notEnoughArguments(0, info.Length()));
    205         exceptionState.throwIfNeeded();
    206         return;
    207     }
    208     exceptionState.throwTypeError("No matching constructor signature.");
    209     exceptionState.throwIfNeeded();
    210 }
    211 
    212 } // namespace TestInterfaceConstructorV8Internal
    213 
    214 const WrapperTypeInfo V8TestInterfaceConstructorConstructor::wrapperTypeInfo = { gin::kEmbedderBlink, V8TestInterfaceConstructorConstructor::domTemplate, V8TestInterfaceConstructor::refObject, V8TestInterfaceConstructor::derefObject, V8TestInterfaceConstructor::createPersistentHandle, 0, 0, 0, V8TestInterfaceConstructor::installConditionallyEnabledMethods, V8TestInterfaceConstructor::installConditionallyEnabledProperties, 0, WrapperTypeInfo::WrapperTypeObjectPrototype, WrapperTypeInfo::ObjectClassId, WrapperTypeInfo::Independent, WrapperTypeInfo::RefCountedObject };
    215 
    216 static void V8TestInterfaceConstructorConstructorCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
    217 {
    218     if (!info.IsConstructCall()) {
    219         V8ThrowException::throwTypeError(ExceptionMessages::constructorNotCallableAsFunction("Audio"), info.GetIsolate());
    220         return;
    221     }
    222 
    223     if (ConstructorMode::current(info.GetIsolate()) == ConstructorMode::WrapExistingObject) {
    224         v8SetReturnValue(info, info.Holder());
    225         return;
    226     }
    227     ExceptionState exceptionState(ExceptionState::ConstructionContext, "TestInterfaceConstructor", info.Holder(), info.GetIsolate());
    228     if (UNLIKELY(info.Length() < 1)) {
    229         setMinimumArityTypeError(exceptionState, 1, info.Length());
    230         exceptionState.throwIfNeeded();
    231         return;
    232     }
    233     V8StringResource<> arg;
    234     V8StringResource<> optArg;
    235     {
    236         TOSTRING_VOID_INTERNAL(arg, info[0]);
    237         if (UNLIKELY(info.Length() <= 1)) {
    238             ExecutionContext* executionContext = currentExecutionContext(info.GetIsolate());
    239             Document& document = *toDocument(currentExecutionContext(info.GetIsolate()));
    240             RefPtr<TestInterfaceConstructor> impl = TestInterfaceConstructor::createForJSConstructor(executionContext, document, arg, exceptionState);
    241             if (exceptionState.hadException()) {
    242                 exceptionState.throwIfNeeded();
    243                 return;
    244             }
    245             v8::Handle<v8::Object> wrapper = info.Holder();
    246             impl->associateWithWrapper(&V8TestInterfaceConstructorConstructor::wrapperTypeInfo, wrapper, info.GetIsolate());
    247             v8SetReturnValue(info, wrapper);
    248             return;
    249         }
    250         TOSTRING_VOID_INTERNAL(optArg, info[1]);
    251     }
    252     ExecutionContext* executionContext = currentExecutionContext(info.GetIsolate());
    253     Document& document = *toDocument(currentExecutionContext(info.GetIsolate()));
    254     RefPtr<TestInterfaceConstructor> impl = TestInterfaceConstructor::createForJSConstructor(executionContext, document, arg, optArg, exceptionState);
    255     if (exceptionState.hadException()) {
    256         exceptionState.throwIfNeeded();
    257         return;
    258     }
    259     v8::Handle<v8::Object> wrapper = info.Holder();
    260     impl->associateWithWrapper(&V8TestInterfaceConstructorConstructor::wrapperTypeInfo, wrapper, info.GetIsolate());
    261     v8SetReturnValue(info, wrapper);
    262 }
    263 
    264 v8::Handle<v8::FunctionTemplate> V8TestInterfaceConstructorConstructor::domTemplate(v8::Isolate* isolate)
    265 {
    266     static int domTemplateKey; // This address is used for a key to look up the dom template.
    267     V8PerIsolateData* data = V8PerIsolateData::from(isolate);
    268     v8::Local<v8::FunctionTemplate> result = data->existingDOMTemplate(&domTemplateKey);
    269     if (!result.IsEmpty())
    270         return result;
    271 
    272     TRACE_EVENT_SCOPED_SAMPLING_STATE("blink", "BuildDOMTemplate");
    273     result = v8::FunctionTemplate::New(isolate, V8TestInterfaceConstructorConstructorCallback);
    274     v8::Local<v8::ObjectTemplate> instanceTemplate = result->InstanceTemplate();
    275     instanceTemplate->SetInternalFieldCount(V8TestInterfaceConstructor::internalFieldCount);
    276     result->SetClassName(v8AtomicString(isolate, "TestInterfaceConstructor"));
    277     result->Inherit(V8TestInterfaceConstructor::domTemplate(isolate));
    278     data->setDOMTemplate(&domTemplateKey, result);
    279     return result;
    280 }
    281 
    282 void V8TestInterfaceConstructor::constructorCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
    283 {
    284     TRACE_EVENT_SCOPED_SAMPLING_STATE("blink", "DOMConstructor");
    285     UseCounter::count(callingExecutionContext(info.GetIsolate()), UseCounter::TestFeature);
    286     if (!info.IsConstructCall()) {
    287         V8ThrowException::throwTypeError(ExceptionMessages::constructorNotCallableAsFunction("TestInterfaceConstructor"), info.GetIsolate());
    288         return;
    289     }
    290 
    291     if (ConstructorMode::current(info.GetIsolate()) == ConstructorMode::WrapExistingObject) {
    292         v8SetReturnValue(info, info.Holder());
    293         return;
    294     }
    295 
    296     TestInterfaceConstructorV8Internal::constructor(info);
    297 }
    298 
    299 static void installV8TestInterfaceConstructorTemplate(v8::Handle<v8::FunctionTemplate> functionTemplate, v8::Isolate* isolate)
    300 {
    301     functionTemplate->ReadOnlyPrototype();
    302 
    303     v8::Local<v8::Signature> defaultSignature;
    304     defaultSignature = V8DOMConfiguration::installDOMClassTemplate(functionTemplate, "TestInterfaceConstructor", v8::Local<v8::FunctionTemplate>(), V8TestInterfaceConstructor::internalFieldCount,
    305         0, 0,
    306         0, 0,
    307         0, 0,
    308         isolate);
    309     functionTemplate->SetCallHandler(V8TestInterfaceConstructor::constructorCallback);
    310     functionTemplate->SetLength(0);
    311     v8::Local<v8::ObjectTemplate> instanceTemplate ALLOW_UNUSED = functionTemplate->InstanceTemplate();
    312     v8::Local<v8::ObjectTemplate> prototypeTemplate ALLOW_UNUSED = functionTemplate->PrototypeTemplate();
    313 
    314     // Custom toString template
    315     functionTemplate->Set(v8AtomicString(isolate, "toString"), V8PerIsolateData::from(isolate)->toStringTemplate());
    316 }
    317 
    318 v8::Handle<v8::FunctionTemplate> V8TestInterfaceConstructor::domTemplate(v8::Isolate* isolate)
    319 {
    320     return V8DOMConfiguration::domClassTemplate(isolate, const_cast<WrapperTypeInfo*>(&wrapperTypeInfo), installV8TestInterfaceConstructorTemplate);
    321 }
    322 
    323 bool V8TestInterfaceConstructor::hasInstance(v8::Handle<v8::Value> v8Value, v8::Isolate* isolate)
    324 {
    325     return V8PerIsolateData::from(isolate)->hasInstance(&wrapperTypeInfo, v8Value);
    326 }
    327 
    328 v8::Handle<v8::Object> V8TestInterfaceConstructor::findInstanceInPrototypeChain(v8::Handle<v8::Value> v8Value, v8::Isolate* isolate)
    329 {
    330     return V8PerIsolateData::from(isolate)->findInstanceInPrototypeChain(&wrapperTypeInfo, v8Value);
    331 }
    332 
    333 TestInterfaceConstructor* V8TestInterfaceConstructor::toImplWithTypeCheck(v8::Isolate* isolate, v8::Handle<v8::Value> value)
    334 {
    335     return hasInstance(value, isolate) ? blink::toScriptWrappableBase(v8::Handle<v8::Object>::Cast(value))->toImpl<TestInterfaceConstructor>() : 0;
    336 }
    337 
    338 
    339 void V8TestInterfaceConstructor::refObject(ScriptWrappableBase* internalPointer)
    340 {
    341     internalPointer->toImpl<TestInterfaceConstructor>()->ref();
    342 }
    343 
    344 void V8TestInterfaceConstructor::derefObject(ScriptWrappableBase* internalPointer)
    345 {
    346     internalPointer->toImpl<TestInterfaceConstructor>()->deref();
    347 }
    348 
    349 WrapperPersistentNode* V8TestInterfaceConstructor::createPersistentHandle(ScriptWrappableBase* internalPointer)
    350 {
    351     ASSERT_NOT_REACHED();
    352     return 0;
    353 }
    354 
    355 template<>
    356 v8::Handle<v8::Value> toV8NoInline(TestInterfaceConstructor* impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
    357 {
    358     return toV8(impl, creationContext, isolate);
    359 }
    360 
    361 } // namespace blink
    362