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 "V8TestSpecialOperations.h" 9 10 #include "bindings/core/v8/V8NodeList.h" 11 #include "bindings/tests/v8/V8Node.h" 12 #include "bindings/v8/ExceptionState.h" 13 #include "bindings/v8/V8DOMConfiguration.h" 14 #include "bindings/v8/V8HiddenValue.h" 15 #include "bindings/v8/V8ObjectConstructor.h" 16 #include "core/dom/ContextFeatures.h" 17 #include "core/dom/Document.h" 18 #include "core/dom/NameNodeList.h" 19 #include "core/dom/NodeList.h" 20 #include "core/dom/StaticNodeList.h" 21 #include "core/html/LabelsNodeList.h" 22 #include "platform/RuntimeEnabledFeatures.h" 23 #include "platform/TraceEvent.h" 24 #include "wtf/GetPtr.h" 25 #include "wtf/RefPtr.h" 26 27 namespace WebCore { 28 29 static void initializeScriptWrappableForInterface(TestSpecialOperations* object) 30 { 31 if (ScriptWrappable::wrapperCanBeStoredInObject(object)) 32 ScriptWrappable::fromObject(object)->setTypeInfo(&V8TestSpecialOperations::wrapperTypeInfo); 33 else 34 ASSERT_NOT_REACHED(); 35 } 36 37 } // namespace WebCore 38 39 void webCoreInitializeScriptWrappableForInterface(WebCore::TestSpecialOperations* object) 40 { 41 WebCore::initializeScriptWrappableForInterface(object); 42 } 43 44 namespace WebCore { 45 const WrapperTypeInfo V8TestSpecialOperations::wrapperTypeInfo = { gin::kEmbedderBlink, V8TestSpecialOperations::domTemplate, V8TestSpecialOperations::derefObject, 0, 0, 0, V8TestSpecialOperations::installPerContextEnabledMethods, 0, WrapperTypeObjectPrototype, RefCountedObject }; 46 47 namespace TestSpecialOperationsV8Internal { 48 49 template <typename T> void V8_USE(T) { } 50 51 static void namedItemMethod(const v8::FunctionCallbackInfo<v8::Value>& info) 52 { 53 if (UNLIKELY(info.Length() < 1)) { 54 throwMinimumArityTypeErrorForMethod("namedItem", "TestSpecialOperations", 1, info.Length(), info.GetIsolate()); 55 return; 56 } 57 TestSpecialOperations* impl = V8TestSpecialOperations::toNative(info.Holder()); 58 V8StringResource<> name; 59 { 60 TOSTRING_VOID_INTERNAL(name, info[0]); 61 } 62 bool result0Enabled = false; 63 RefPtrWillBeRawPtr<Node> result0; 64 bool result1Enabled = false; 65 RefPtrWillBeRawPtr<NodeList> result1; 66 impl->getItem(name, result0Enabled, result0, result1Enabled, result1); 67 if (result0Enabled) { 68 v8SetReturnValue(info, result0.release()); 69 return; 70 } 71 if (result1Enabled) { 72 v8SetReturnValue(info, result1.release()); 73 return; 74 } 75 v8SetReturnValueNull(info); 76 } 77 78 static void namedItemMethodCallback(const v8::FunctionCallbackInfo<v8::Value>& info) 79 { 80 TRACE_EVENT_SET_SAMPLING_STATE("Blink", "DOMMethod"); 81 TestSpecialOperationsV8Internal::namedItemMethod(info); 82 TRACE_EVENT_SET_SAMPLING_STATE("V8", "V8Execution"); 83 } 84 85 static void namedPropertyGetter(v8::Local<v8::String> name, const v8::PropertyCallbackInfo<v8::Value>& info) 86 { 87 TestSpecialOperations* impl = V8TestSpecialOperations::toNative(info.Holder()); 88 AtomicString propertyName = toCoreAtomicString(name); 89 bool result0Enabled = false; 90 RefPtrWillBeRawPtr<Node> result0; 91 bool result1Enabled = false; 92 RefPtrWillBeRawPtr<NodeList> result1; 93 impl->getItem(propertyName, result0Enabled, result0, result1Enabled, result1); 94 if (!result0Enabled && !result1Enabled) 95 return; 96 if (result0Enabled) { 97 v8SetReturnValueFast(info, WTF::getPtr(result0.release()), impl); 98 return; 99 } 100 if (result1Enabled) { 101 v8SetReturnValueFast(info, WTF::getPtr(result1.release()), impl); 102 return; 103 } 104 v8SetReturnValueNull(info); 105 } 106 107 static void namedPropertyGetterCallback(v8::Local<v8::String> name, const v8::PropertyCallbackInfo<v8::Value>& info) 108 { 109 TRACE_EVENT_SET_SAMPLING_STATE("Blink", "DOMNamedProperty"); 110 TestSpecialOperationsV8Internal::namedPropertyGetter(name, info); 111 TRACE_EVENT_SET_SAMPLING_STATE("V8", "V8Execution"); 112 } 113 114 static void namedPropertySetter(v8::Local<v8::String> name, v8::Local<v8::Value> v8Value, const v8::PropertyCallbackInfo<v8::Value>& info) 115 { 116 TestSpecialOperations* impl = V8TestSpecialOperations::toNative(info.Holder()); 117 TOSTRING_VOID(V8StringResource<>, propertyName, name); 118 TONATIVE_VOID(Node*, propertyValue, V8Node::toNativeWithTypeCheck(info.GetIsolate(), v8Value)); 119 bool result = impl->anonymousNamedSetter(propertyName, propertyValue); 120 if (!result) 121 return; 122 v8SetReturnValue(info, v8Value); 123 } 124 125 static void namedPropertySetterCallback(v8::Local<v8::String> name, v8::Local<v8::Value> v8Value, const v8::PropertyCallbackInfo<v8::Value>& info) 126 { 127 TRACE_EVENT_SET_SAMPLING_STATE("Blink", "DOMNamedProperty"); 128 TestSpecialOperationsV8Internal::namedPropertySetter(name, v8Value, info); 129 TRACE_EVENT_SET_SAMPLING_STATE("V8", "V8Execution"); 130 } 131 132 static void namedPropertyQuery(v8::Local<v8::String> name, const v8::PropertyCallbackInfo<v8::Integer>& info) 133 { 134 TestSpecialOperations* impl = V8TestSpecialOperations::toNative(info.Holder()); 135 AtomicString propertyName = toCoreAtomicString(name); 136 v8::String::Utf8Value namedProperty(name); 137 ExceptionState exceptionState(ExceptionState::GetterContext, *namedProperty, "TestSpecialOperations", info.Holder(), info.GetIsolate()); 138 bool result = impl->namedPropertyQuery(propertyName, exceptionState); 139 if (exceptionState.throwIfNeeded()) 140 return; 141 if (!result) 142 return; 143 v8SetReturnValueInt(info, v8::None); 144 } 145 146 static void namedPropertyQueryCallback(v8::Local<v8::String> name, const v8::PropertyCallbackInfo<v8::Integer>& info) 147 { 148 TRACE_EVENT_SET_SAMPLING_STATE("Blink", "DOMNamedProperty"); 149 TestSpecialOperationsV8Internal::namedPropertyQuery(name, info); 150 TRACE_EVENT_SET_SAMPLING_STATE("V8", "V8Execution"); 151 } 152 153 static void namedPropertyEnumerator(const v8::PropertyCallbackInfo<v8::Array>& info) 154 { 155 TestSpecialOperations* impl = V8TestSpecialOperations::toNative(info.Holder()); 156 v8::Isolate* isolate = info.GetIsolate(); 157 Vector<String> names; 158 ExceptionState exceptionState(ExceptionState::EnumerationContext, "TestSpecialOperations", info.Holder(), isolate); 159 impl->namedPropertyEnumerator(names, exceptionState); 160 if (exceptionState.throwIfNeeded()) 161 return; 162 v8::Handle<v8::Array> v8names = v8::Array::New(isolate, names.size()); 163 for (size_t i = 0; i < names.size(); ++i) 164 v8names->Set(v8::Integer::New(isolate, i), v8String(isolate, names[i])); 165 v8SetReturnValue(info, v8names); 166 } 167 168 static void namedPropertyEnumeratorCallback(const v8::PropertyCallbackInfo<v8::Array>& info) 169 { 170 TRACE_EVENT_SET_SAMPLING_STATE("Blink", "DOMNamedProperty"); 171 TestSpecialOperationsV8Internal::namedPropertyEnumerator(info); 172 TRACE_EVENT_SET_SAMPLING_STATE("V8", "V8Execution"); 173 } 174 175 } // namespace TestSpecialOperationsV8Internal 176 177 static const V8DOMConfiguration::MethodConfiguration V8TestSpecialOperationsMethods[] = { 178 {"namedItem", TestSpecialOperationsV8Internal::namedItemMethodCallback, 0, 1}, 179 }; 180 181 static void configureV8TestSpecialOperationsTemplate(v8::Handle<v8::FunctionTemplate> functionTemplate, v8::Isolate* isolate) 182 { 183 functionTemplate->ReadOnlyPrototype(); 184 185 v8::Local<v8::Signature> defaultSignature; 186 defaultSignature = V8DOMConfiguration::installDOMClassTemplate(functionTemplate, "TestSpecialOperations", v8::Local<v8::FunctionTemplate>(), V8TestSpecialOperations::internalFieldCount, 187 0, 0, 188 0, 0, 189 V8TestSpecialOperationsMethods, WTF_ARRAY_LENGTH(V8TestSpecialOperationsMethods), 190 isolate); 191 v8::Local<v8::ObjectTemplate> instanceTemplate ALLOW_UNUSED = functionTemplate->InstanceTemplate(); 192 v8::Local<v8::ObjectTemplate> prototypeTemplate ALLOW_UNUSED = functionTemplate->PrototypeTemplate(); 193 functionTemplate->InstanceTemplate()->SetNamedPropertyHandler(TestSpecialOperationsV8Internal::namedPropertyGetterCallback, TestSpecialOperationsV8Internal::namedPropertySetterCallback, TestSpecialOperationsV8Internal::namedPropertyQueryCallback, 0, TestSpecialOperationsV8Internal::namedPropertyEnumeratorCallback); 194 195 // Custom toString template 196 functionTemplate->Set(v8AtomicString(isolate, "toString"), V8PerIsolateData::from(isolate)->toStringTemplate()); 197 } 198 199 v8::Handle<v8::FunctionTemplate> V8TestSpecialOperations::domTemplate(v8::Isolate* isolate) 200 { 201 return V8DOMConfiguration::domClassTemplate(isolate, const_cast<WrapperTypeInfo*>(&wrapperTypeInfo), configureV8TestSpecialOperationsTemplate); 202 } 203 204 bool V8TestSpecialOperations::hasInstance(v8::Handle<v8::Value> v8Value, v8::Isolate* isolate) 205 { 206 return V8PerIsolateData::from(isolate)->hasInstance(&wrapperTypeInfo, v8Value); 207 } 208 209 v8::Handle<v8::Object> V8TestSpecialOperations::findInstanceInPrototypeChain(v8::Handle<v8::Value> v8Value, v8::Isolate* isolate) 210 { 211 return V8PerIsolateData::from(isolate)->findInstanceInPrototypeChain(&wrapperTypeInfo, v8Value); 212 } 213 214 TestSpecialOperations* V8TestSpecialOperations::toNativeWithTypeCheck(v8::Isolate* isolate, v8::Handle<v8::Value> value) 215 { 216 return hasInstance(value, isolate) ? fromInternalPointer(v8::Handle<v8::Object>::Cast(value)->GetAlignedPointerFromInternalField(v8DOMWrapperObjectIndex)) : 0; 217 } 218 219 v8::Handle<v8::Object> wrap(TestSpecialOperations* impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate) 220 { 221 ASSERT(impl); 222 ASSERT(!DOMDataStore::containsWrapper<V8TestSpecialOperations>(impl, isolate)); 223 return V8TestSpecialOperations::createWrapper(impl, creationContext, isolate); 224 } 225 226 v8::Handle<v8::Object> V8TestSpecialOperations::createWrapper(PassRefPtr<TestSpecialOperations> impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate) 227 { 228 ASSERT(impl); 229 ASSERT(!DOMDataStore::containsWrapper<V8TestSpecialOperations>(impl.get(), isolate)); 230 if (ScriptWrappable::wrapperCanBeStoredInObject(impl.get())) { 231 const WrapperTypeInfo* actualInfo = ScriptWrappable::fromObject(impl.get())->typeInfo(); 232 // Might be a XXXConstructor::wrapperTypeInfo instead of an XXX::wrapperTypeInfo. These will both have 233 // the same object de-ref functions, though, so use that as the basis of the check. 234 RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(actualInfo->derefObjectFunction == wrapperTypeInfo.derefObjectFunction); 235 } 236 237 v8::Handle<v8::Object> wrapper = V8DOMWrapper::createWrapper(creationContext, &wrapperTypeInfo, toInternalPointer(impl.get()), isolate); 238 if (UNLIKELY(wrapper.IsEmpty())) 239 return wrapper; 240 241 installPerContextEnabledProperties(wrapper, impl.get(), isolate); 242 V8DOMWrapper::associateObjectWithWrapper<V8TestSpecialOperations>(impl, &wrapperTypeInfo, wrapper, isolate, WrapperConfiguration::Independent); 243 return wrapper; 244 } 245 246 void V8TestSpecialOperations::derefObject(void* object) 247 { 248 fromInternalPointer(object)->deref(); 249 } 250 251 template<> 252 v8::Handle<v8::Value> toV8NoInline(TestSpecialOperations* impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate) 253 { 254 return toV8(impl, creationContext, isolate); 255 } 256 257 } // namespace WebCore 258