1 /* 2 This file is part of the Blink open source project. 3 This file has been auto-generated by CodeGeneratorV8.pm. DO NOT MODIFY! 4 5 This library is free software; you can redistribute it and/or 6 modify it under the terms of the GNU Library General Public 7 License as published by the Free Software Foundation; either 8 version 2 of the License, or (at your option) any later version. 9 10 This library is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 Library General Public License for more details. 14 15 You should have received a copy of the GNU Library General Public License 16 along with this library; see the file COPYING.LIB. If not, write to 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18 Boston, MA 02111-1307, USA. 19 */ 20 21 #include "config.h" 22 #include "V8TestOverloadedConstructors.h" 23 24 #include "RuntimeEnabledFeatures.h" 25 #include "V8Blob.h" 26 #include "bindings/v8/ExceptionState.h" 27 #include "bindings/v8/ScriptController.h" 28 #include "bindings/v8/V8Binding.h" 29 #include "bindings/v8/V8DOMConfiguration.h" 30 #include "bindings/v8/V8DOMWrapper.h" 31 #include "bindings/v8/V8ObjectConstructor.h" 32 #include "bindings/v8/custom/V8ArrayBufferCustom.h" 33 #include "bindings/v8/custom/V8ArrayBufferViewCustom.h" 34 #include "core/dom/ContextFeatures.h" 35 #include "core/dom/Document.h" 36 #include "core/page/Frame.h" 37 #include "core/platform/chromium/TraceEvent.h" 38 #include "wtf/UnusedParam.h" 39 40 namespace WebCore { 41 42 static void initializeScriptWrappableForInterface(TestOverloadedConstructors* object) 43 { 44 if (ScriptWrappable::wrapperCanBeStoredInObject(object)) 45 ScriptWrappable::setTypeInfoInObject(object, &V8TestOverloadedConstructors::info); 46 else 47 ASSERT_NOT_REACHED(); 48 } 49 50 } // namespace WebCore 51 52 // In ScriptWrappable::init, the use of a local function declaration has an issue on Windows: 53 // the local declaration does not pick up the surrounding namespace. Therefore, we provide this function 54 // in the global namespace. 55 // (More info on the MSVC bug here: http://connect.microsoft.com/VisualStudio/feedback/details/664619/the-namespace-of-local-function-declarations-in-c) 56 void webCoreInitializeScriptWrappableForInterface(WebCore::TestOverloadedConstructors* object) 57 { 58 WebCore::initializeScriptWrappableForInterface(object); 59 } 60 61 namespace WebCore { 62 WrapperTypeInfo V8TestOverloadedConstructors::info = { V8TestOverloadedConstructors::GetTemplate, V8TestOverloadedConstructors::derefObject, 0, 0, 0, V8TestOverloadedConstructors::installPerContextPrototypeProperties, 0, WrapperTypeObjectPrototype }; 63 64 namespace TestOverloadedConstructorsV8Internal { 65 66 template <typename T> void V8_USE(T) { } 67 68 static void constructor1(const v8::FunctionCallbackInfo<v8::Value>& args) 69 { 70 V8TRYCATCH_VOID(ArrayBuffer*, arrayBuffer, args[0]->IsArrayBuffer() ? V8ArrayBuffer::toNative(v8::Handle<v8::ArrayBuffer>::Cast(args[0])) : 0); 71 72 RefPtr<TestOverloadedConstructors> impl = TestOverloadedConstructors::create(arrayBuffer); 73 v8::Handle<v8::Object> wrapper = args.Holder(); 74 75 V8DOMWrapper::associateObjectWithWrapper<V8TestOverloadedConstructors>(impl.release(), &V8TestOverloadedConstructors::info, wrapper, args.GetIsolate(), WrapperConfiguration::Dependent); 76 args.GetReturnValue().Set(wrapper); 77 } 78 79 static void constructor2(const v8::FunctionCallbackInfo<v8::Value>& args) 80 { 81 V8TRYCATCH_VOID(ArrayBufferView*, arrayBufferView, args[0]->IsArrayBufferView() ? V8ArrayBufferView::toNative(v8::Handle<v8::ArrayBufferView>::Cast(args[0])) : 0); 82 83 RefPtr<TestOverloadedConstructors> impl = TestOverloadedConstructors::create(arrayBufferView); 84 v8::Handle<v8::Object> wrapper = args.Holder(); 85 86 V8DOMWrapper::associateObjectWithWrapper<V8TestOverloadedConstructors>(impl.release(), &V8TestOverloadedConstructors::info, wrapper, args.GetIsolate(), WrapperConfiguration::Dependent); 87 args.GetReturnValue().Set(wrapper); 88 } 89 90 static void constructor3(const v8::FunctionCallbackInfo<v8::Value>& args) 91 { 92 V8TRYCATCH_VOID(Blob*, blob, V8Blob::HasInstance(args[0], args.GetIsolate(), worldType(args.GetIsolate())) ? V8Blob::toNative(v8::Handle<v8::Object>::Cast(args[0])) : 0); 93 94 RefPtr<TestOverloadedConstructors> impl = TestOverloadedConstructors::create(blob); 95 v8::Handle<v8::Object> wrapper = args.Holder(); 96 97 V8DOMWrapper::associateObjectWithWrapper<V8TestOverloadedConstructors>(impl.release(), &V8TestOverloadedConstructors::info, wrapper, args.GetIsolate(), WrapperConfiguration::Dependent); 98 args.GetReturnValue().Set(wrapper); 99 } 100 101 static void constructor4(const v8::FunctionCallbackInfo<v8::Value>& args) 102 { 103 V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<>, string, args[0]); 104 105 RefPtr<TestOverloadedConstructors> impl = TestOverloadedConstructors::create(string); 106 v8::Handle<v8::Object> wrapper = args.Holder(); 107 108 V8DOMWrapper::associateObjectWithWrapper<V8TestOverloadedConstructors>(impl.release(), &V8TestOverloadedConstructors::info, wrapper, args.GetIsolate(), WrapperConfiguration::Dependent); 109 args.GetReturnValue().Set(wrapper); 110 } 111 112 static void constructor(const v8::FunctionCallbackInfo<v8::Value>& args) 113 { 114 if ((args.Length() == 1 && (V8ArrayBuffer::HasInstance(args[0], args.GetIsolate(), worldType(args.GetIsolate()))))) { 115 TestOverloadedConstructorsV8Internal::constructor1(args); 116 return; 117 } 118 if ((args.Length() == 1 && (V8ArrayBufferView::HasInstance(args[0], args.GetIsolate(), worldType(args.GetIsolate()))))) { 119 TestOverloadedConstructorsV8Internal::constructor2(args); 120 return; 121 } 122 if ((args.Length() == 1 && (V8Blob::HasInstance(args[0], args.GetIsolate(), worldType(args.GetIsolate()))))) { 123 TestOverloadedConstructorsV8Internal::constructor3(args); 124 return; 125 } 126 if (args.Length() == 1) { 127 TestOverloadedConstructorsV8Internal::constructor4(args); 128 return; 129 } 130 if (args.Length() < 1) { 131 throwNotEnoughArgumentsError(args.GetIsolate()); 132 return; 133 } 134 throwTypeError(args.GetIsolate()); 135 return; 136 } 137 138 } // namespace TestOverloadedConstructorsV8Internal 139 140 void V8TestOverloadedConstructors::constructorCallback(const v8::FunctionCallbackInfo<v8::Value>& args) 141 { 142 TRACE_EVENT_SCOPED_SAMPLING_STATE("Blink", "DOMConstructor"); 143 if (!args.IsConstructCall()) { 144 throwTypeError("DOM object constructor cannot be called as a function.", args.GetIsolate()); 145 return; 146 } 147 148 if (ConstructorMode::current() == ConstructorMode::WrapExistingObject) { 149 args.GetReturnValue().Set(args.Holder()); 150 return; 151 } 152 153 TestOverloadedConstructorsV8Internal::constructor(args); 154 } 155 156 static v8::Handle<v8::FunctionTemplate> ConfigureV8TestOverloadedConstructorsTemplate(v8::Handle<v8::FunctionTemplate> desc, v8::Isolate* isolate, WrapperWorldType currentWorldType) 157 { 158 desc->ReadOnlyPrototype(); 159 160 v8::Local<v8::Signature> defaultSignature; 161 defaultSignature = V8DOMConfiguration::configureTemplate(desc, "TestOverloadedConstructors", v8::Local<v8::FunctionTemplate>(), V8TestOverloadedConstructors::internalFieldCount, 162 0, 0, 163 0, 0, isolate, currentWorldType); 164 UNUSED_PARAM(defaultSignature); // In some cases, it will not be used. 165 desc->SetCallHandler(V8TestOverloadedConstructors::constructorCallback); 166 desc->SetLength(1); 167 168 // Custom toString template 169 desc->Set(v8::String::NewSymbol("toString"), V8PerIsolateData::current()->toStringTemplate()); 170 return desc; 171 } 172 173 v8::Handle<v8::FunctionTemplate> V8TestOverloadedConstructors::GetTemplate(v8::Isolate* isolate, WrapperWorldType currentWorldType) 174 { 175 V8PerIsolateData* data = V8PerIsolateData::from(isolate); 176 V8PerIsolateData::TemplateMap::iterator result = data->templateMap(currentWorldType).find(&info); 177 if (result != data->templateMap(currentWorldType).end()) 178 return result->value.newLocal(isolate); 179 180 TRACE_EVENT_SCOPED_SAMPLING_STATE("Blink", "BuildDOMTemplate"); 181 v8::HandleScope handleScope(isolate); 182 v8::Handle<v8::FunctionTemplate> templ = 183 ConfigureV8TestOverloadedConstructorsTemplate(data->rawTemplate(&info, currentWorldType), isolate, currentWorldType); 184 data->templateMap(currentWorldType).add(&info, UnsafePersistent<v8::FunctionTemplate>(isolate, templ)); 185 return handleScope.Close(templ); 186 } 187 188 bool V8TestOverloadedConstructors::HasInstance(v8::Handle<v8::Value> value, v8::Isolate* isolate, WrapperWorldType currentWorldType) 189 { 190 return V8PerIsolateData::from(isolate)->hasInstance(&info, value, currentWorldType); 191 } 192 193 bool V8TestOverloadedConstructors::HasInstanceInAnyWorld(v8::Handle<v8::Value> value, v8::Isolate* isolate) 194 { 195 return V8PerIsolateData::from(isolate)->hasInstance(&info, value, MainWorld) 196 || V8PerIsolateData::from(isolate)->hasInstance(&info, value, IsolatedWorld) 197 || V8PerIsolateData::from(isolate)->hasInstance(&info, value, WorkerWorld); 198 } 199 200 201 v8::Handle<v8::Object> V8TestOverloadedConstructors::createWrapper(PassRefPtr<TestOverloadedConstructors> impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate) 202 { 203 ASSERT(impl.get()); 204 ASSERT(DOMDataStore::getWrapper<V8TestOverloadedConstructors>(impl.get(), isolate).IsEmpty()); 205 if (ScriptWrappable::wrapperCanBeStoredInObject(impl.get())) { 206 const WrapperTypeInfo* actualInfo = ScriptWrappable::getTypeInfoFromObject(impl.get()); 207 // Might be a XXXConstructor::info instead of an XXX::info. These will both have 208 // the same object de-ref functions, though, so use that as the basis of the check. 209 RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(actualInfo->derefObjectFunction == info.derefObjectFunction); 210 } 211 212 213 v8::Handle<v8::Object> wrapper = V8DOMWrapper::createWrapper(creationContext, &info, toInternalPointer(impl.get()), isolate); 214 if (UNLIKELY(wrapper.IsEmpty())) 215 return wrapper; 216 installPerContextProperties(wrapper, impl.get(), isolate); 217 V8DOMWrapper::associateObjectWithWrapper<V8TestOverloadedConstructors>(impl, &info, wrapper, isolate, WrapperConfiguration::Independent); 218 return wrapper; 219 } 220 void V8TestOverloadedConstructors::derefObject(void* object) 221 { 222 fromInternalPointer(object)->deref(); 223 } 224 225 } // namespace WebCore 226