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 "V8TestInterfaceImplementedAs.h" 23 24 #include "RuntimeEnabledFeatures.h" 25 #include "bindings/v8/ExceptionState.h" 26 #include "bindings/v8/ScriptController.h" 27 #include "bindings/v8/V8Binding.h" 28 #include "bindings/v8/V8DOMConfiguration.h" 29 #include "bindings/v8/V8DOMWrapper.h" 30 #include "core/dom/ContextFeatures.h" 31 #include "core/dom/Document.h" 32 #include "core/page/Frame.h" 33 #include "core/platform/chromium/TraceEvent.h" 34 #include "wtf/GetPtr.h" 35 #include "wtf/RefPtr.h" 36 #include "wtf/UnusedParam.h" 37 38 namespace WebCore { 39 40 static void initializeScriptWrappableForInterface(RealClass* object) 41 { 42 if (ScriptWrappable::wrapperCanBeStoredInObject(object)) 43 ScriptWrappable::setTypeInfoInObject(object, &V8TestInterfaceImplementedAs::info); 44 else 45 ASSERT_NOT_REACHED(); 46 } 47 48 } // namespace WebCore 49 50 // In ScriptWrappable::init, the use of a local function declaration has an issue on Windows: 51 // the local declaration does not pick up the surrounding namespace. Therefore, we provide this function 52 // in the global namespace. 53 // (More info on the MSVC bug here: http://connect.microsoft.com/VisualStudio/feedback/details/664619/the-namespace-of-local-function-declarations-in-c) 54 void webCoreInitializeScriptWrappableForInterface(WebCore::RealClass* object) 55 { 56 WebCore::initializeScriptWrappableForInterface(object); 57 } 58 59 namespace WebCore { 60 WrapperTypeInfo V8TestInterfaceImplementedAs::info = { V8TestInterfaceImplementedAs::GetTemplate, V8TestInterfaceImplementedAs::derefObject, 0, 0, 0, V8TestInterfaceImplementedAs::installPerContextPrototypeProperties, 0, WrapperTypeObjectPrototype }; 61 62 namespace RealClassV8Internal { 63 64 template <typename T> void V8_USE(T) { } 65 66 static void aAttrGetter(v8::Local<v8::String> name, const v8::PropertyCallbackInfo<v8::Value>& info) 67 { 68 RealClass* imp = V8TestInterfaceImplementedAs::toNative(info.Holder()); 69 v8SetReturnValueString(info, imp->a(), info.GetIsolate()); 70 return; 71 } 72 73 static void aAttrGetterCallback(v8::Local<v8::String> name, const v8::PropertyCallbackInfo<v8::Value>& info) 74 { 75 TRACE_EVENT_SET_SAMPLING_STATE("Blink", "DOMGetter"); 76 RealClassV8Internal::aAttrGetter(name, info); 77 TRACE_EVENT_SET_SAMPLING_STATE("V8", "Execution"); 78 } 79 80 static void aAttrSetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<void>& info) 81 { 82 RealClass* imp = V8TestInterfaceImplementedAs::toNative(info.Holder()); 83 V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<>, v, value); 84 imp->setA(v); 85 return; 86 } 87 88 static void aAttrSetterCallback(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<void>& info) 89 { 90 TRACE_EVENT_SET_SAMPLING_STATE("Blink", "DOMSetter"); 91 RealClassV8Internal::aAttrSetter(name, value, info); 92 TRACE_EVENT_SET_SAMPLING_STATE("V8", "Execution"); 93 } 94 95 static void bAttrGetter(v8::Local<v8::String> name, const v8::PropertyCallbackInfo<v8::Value>& info) 96 { 97 RealClass* imp = V8TestInterfaceImplementedAs::toNative(info.Holder()); 98 v8SetReturnValue(info, toV8Fast(imp->b(), info, imp)); 99 return; 100 } 101 102 static void bAttrGetterCallback(v8::Local<v8::String> name, const v8::PropertyCallbackInfo<v8::Value>& info) 103 { 104 TRACE_EVENT_SET_SAMPLING_STATE("Blink", "DOMGetter"); 105 RealClassV8Internal::bAttrGetter(name, info); 106 TRACE_EVENT_SET_SAMPLING_STATE("V8", "Execution"); 107 } 108 109 static void bAttrSetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<void>& info) 110 { 111 RealClass* imp = V8TestInterfaceImplementedAs::toNative(info.Holder()); 112 V8TRYCATCH_VOID(RealClass*, v, V8TestInterfaceImplementedAs::HasInstance(value, info.GetIsolate(), worldType(info.GetIsolate())) ? V8TestInterfaceImplementedAs::toNative(v8::Handle<v8::Object>::Cast(value)) : 0); 113 imp->setB(WTF::getPtr(v)); 114 return; 115 } 116 117 static void bAttrSetterCallback(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<void>& info) 118 { 119 TRACE_EVENT_SET_SAMPLING_STATE("Blink", "DOMSetter"); 120 RealClassV8Internal::bAttrSetter(name, value, info); 121 TRACE_EVENT_SET_SAMPLING_STATE("V8", "Execution"); 122 } 123 124 static void func1Method(const v8::FunctionCallbackInfo<v8::Value>& args) 125 { 126 if (args.Length() < 1) { 127 throwNotEnoughArgumentsError(args.GetIsolate()); 128 return; 129 } 130 RealClass* imp = V8TestInterfaceImplementedAs::toNative(args.Holder()); 131 V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<>, a, args[0]); 132 v8SetReturnValueString(args, imp->func1(a), args.GetIsolate()); 133 return; 134 } 135 136 static void func1MethodCallback(const v8::FunctionCallbackInfo<v8::Value>& args) 137 { 138 TRACE_EVENT_SET_SAMPLING_STATE("Blink", "DOMMethod"); 139 RealClassV8Internal::func1Method(args); 140 TRACE_EVENT_SET_SAMPLING_STATE("V8", "Execution"); 141 } 142 143 static void funcTestInterfaceImplementedAsParamMethod(const v8::FunctionCallbackInfo<v8::Value>& args) 144 { 145 if (args.Length() < 1) { 146 throwNotEnoughArgumentsError(args.GetIsolate()); 147 return; 148 } 149 RealClass* imp = V8TestInterfaceImplementedAs::toNative(args.Holder()); 150 V8TRYCATCH_VOID(RealClass*, orange, V8TestInterfaceImplementedAs::HasInstance(args[0], args.GetIsolate(), worldType(args.GetIsolate())) ? V8TestInterfaceImplementedAs::toNative(v8::Handle<v8::Object>::Cast(args[0])) : 0); 151 v8SetReturnValueString(args, imp->funcTestInterfaceImplementedAsParam(orange), args.GetIsolate()); 152 return; 153 } 154 155 static void funcTestInterfaceImplementedAsParamMethodCallback(const v8::FunctionCallbackInfo<v8::Value>& args) 156 { 157 TRACE_EVENT_SET_SAMPLING_STATE("Blink", "DOMMethod"); 158 RealClassV8Internal::funcTestInterfaceImplementedAsParamMethod(args); 159 TRACE_EVENT_SET_SAMPLING_STATE("V8", "Execution"); 160 } 161 162 } // namespace RealClassV8Internal 163 164 static const V8DOMConfiguration::BatchedAttribute V8TestInterfaceImplementedAsAttrs[] = { 165 // Attribute 'a' 166 {"a", RealClassV8Internal::aAttrGetterCallback, RealClassV8Internal::aAttrSetterCallback, 0, 0, 0 /* no data */, static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None), 0 /* on instance */}, 167 // Attribute 'b' 168 {"b", RealClassV8Internal::bAttrGetterCallback, RealClassV8Internal::bAttrSetterCallback, 0, 0, 0 /* no data */, static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None), 0 /* on instance */}, 169 }; 170 171 static const V8DOMConfiguration::BatchedMethod V8TestInterfaceImplementedAsMethods[] = { 172 {"func1", RealClassV8Internal::func1MethodCallback, 0, 1}, 173 }; 174 175 static v8::Handle<v8::FunctionTemplate> ConfigureV8TestInterfaceImplementedAsTemplate(v8::Handle<v8::FunctionTemplate> desc, v8::Isolate* isolate, WrapperWorldType currentWorldType) 176 { 177 desc->ReadOnlyPrototype(); 178 179 v8::Local<v8::Signature> defaultSignature; 180 defaultSignature = V8DOMConfiguration::configureTemplate(desc, "TestInterfaceImplementedAs", v8::Local<v8::FunctionTemplate>(), V8TestInterfaceImplementedAs::internalFieldCount, 181 V8TestInterfaceImplementedAsAttrs, WTF_ARRAY_LENGTH(V8TestInterfaceImplementedAsAttrs), 182 V8TestInterfaceImplementedAsMethods, WTF_ARRAY_LENGTH(V8TestInterfaceImplementedAsMethods), isolate, currentWorldType); 183 UNUSED_PARAM(defaultSignature); // In some cases, it will not be used. 184 v8::Local<v8::ObjectTemplate> instance = desc->InstanceTemplate(); 185 v8::Local<v8::ObjectTemplate> proto = desc->PrototypeTemplate(); 186 UNUSED_PARAM(instance); // In some cases, it will not be used. 187 UNUSED_PARAM(proto); // In some cases, it will not be used. 188 189 // Custom Signature 'funcTestInterfaceImplementedAsParam' 190 const int funcTestInterfaceImplementedAsParamArgc = 1; 191 v8::Handle<v8::FunctionTemplate> funcTestInterfaceImplementedAsParamArgv[funcTestInterfaceImplementedAsParamArgc] = { V8PerIsolateData::from(isolate)->rawTemplate(&V8TestInterfaceImplementedAs::info, currentWorldType) }; 192 v8::Handle<v8::Signature> funcTestInterfaceImplementedAsParamSignature = v8::Signature::New(desc, funcTestInterfaceImplementedAsParamArgc, funcTestInterfaceImplementedAsParamArgv); 193 proto->Set(v8::String::NewSymbol("funcTestInterfaceImplementedAsParam"), v8::FunctionTemplate::New(RealClassV8Internal::funcTestInterfaceImplementedAsParamMethodCallback, v8Undefined(), funcTestInterfaceImplementedAsParamSignature, 1)); 194 195 // Custom toString template 196 desc->Set(v8::String::NewSymbol("toString"), V8PerIsolateData::current()->toStringTemplate()); 197 return desc; 198 } 199 200 v8::Handle<v8::FunctionTemplate> V8TestInterfaceImplementedAs::GetTemplate(v8::Isolate* isolate, WrapperWorldType currentWorldType) 201 { 202 V8PerIsolateData* data = V8PerIsolateData::from(isolate); 203 V8PerIsolateData::TemplateMap::iterator result = data->templateMap(currentWorldType).find(&info); 204 if (result != data->templateMap(currentWorldType).end()) 205 return result->value.newLocal(isolate); 206 207 TRACE_EVENT_SCOPED_SAMPLING_STATE("Blink", "BuildDOMTemplate"); 208 v8::HandleScope handleScope(isolate); 209 v8::Handle<v8::FunctionTemplate> templ = 210 ConfigureV8TestInterfaceImplementedAsTemplate(data->rawTemplate(&info, currentWorldType), isolate, currentWorldType); 211 data->templateMap(currentWorldType).add(&info, UnsafePersistent<v8::FunctionTemplate>(isolate, templ)); 212 return handleScope.Close(templ); 213 } 214 215 bool V8TestInterfaceImplementedAs::HasInstance(v8::Handle<v8::Value> value, v8::Isolate* isolate, WrapperWorldType currentWorldType) 216 { 217 return V8PerIsolateData::from(isolate)->hasInstance(&info, value, currentWorldType); 218 } 219 220 bool V8TestInterfaceImplementedAs::HasInstanceInAnyWorld(v8::Handle<v8::Value> value, v8::Isolate* isolate) 221 { 222 return V8PerIsolateData::from(isolate)->hasInstance(&info, value, MainWorld) 223 || V8PerIsolateData::from(isolate)->hasInstance(&info, value, IsolatedWorld) 224 || V8PerIsolateData::from(isolate)->hasInstance(&info, value, WorkerWorld); 225 } 226 227 228 v8::Handle<v8::Object> V8TestInterfaceImplementedAs::createWrapper(PassRefPtr<RealClass> impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate) 229 { 230 ASSERT(impl.get()); 231 ASSERT(DOMDataStore::getWrapper<V8TestInterfaceImplementedAs>(impl.get(), isolate).IsEmpty()); 232 if (ScriptWrappable::wrapperCanBeStoredInObject(impl.get())) { 233 const WrapperTypeInfo* actualInfo = ScriptWrappable::getTypeInfoFromObject(impl.get()); 234 // Might be a XXXConstructor::info instead of an XXX::info. These will both have 235 // the same object de-ref functions, though, so use that as the basis of the check. 236 RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(actualInfo->derefObjectFunction == info.derefObjectFunction); 237 } 238 239 240 v8::Handle<v8::Object> wrapper = V8DOMWrapper::createWrapper(creationContext, &info, toInternalPointer(impl.get()), isolate); 241 if (UNLIKELY(wrapper.IsEmpty())) 242 return wrapper; 243 installPerContextProperties(wrapper, impl.get(), isolate); 244 V8DOMWrapper::associateObjectWithWrapper<V8TestInterfaceImplementedAs>(impl, &info, wrapper, isolate, WrapperConfiguration::Independent); 245 return wrapper; 246 } 247 void V8TestInterfaceImplementedAs::derefObject(void* object) 248 { 249 fromInternalPointer(object)->deref(); 250 } 251 252 } // namespace WebCore 253