Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 37 #include "V8Interface1.h" | 37 #include "V8Interface1.h" |
| 38 #include "V8Interface2.h" | 38 #include "V8Interface2.h" |
| 39 #include "bindings/v8/ExceptionState.h" | 39 #include "bindings/v8/ExceptionState.h" |
| 40 #include "bindings/v8/V8DOMConfiguration.h" | 40 #include "bindings/v8/V8DOMConfiguration.h" |
| 41 #include "bindings/v8/V8GCController.h" | 41 #include "bindings/v8/V8GCController.h" |
| 42 #include "bindings/v8/V8HiddenValue.h" | 42 #include "bindings/v8/V8HiddenValue.h" |
| 43 #include "bindings/v8/V8ObjectConstructor.h" | 43 #include "bindings/v8/V8ObjectConstructor.h" |
| 44 #include "core/dom/ContextFeatures.h" | 44 #include "core/dom/ContextFeatures.h" |
| 45 #include "core/dom/Document.h" | 45 #include "core/dom/Document.h" |
| 46 #include "core/dom/Element.h" | 46 #include "core/dom/Element.h" |
| 47 #include "core/frame/DOMWindow.h" | |
| 47 #include "platform/TraceEvent.h" | 48 #include "platform/TraceEvent.h" |
| 48 #include "wtf/GetPtr.h" | 49 #include "wtf/GetPtr.h" |
| 49 #include "wtf/RefPtr.h" | 50 #include "wtf/RefPtr.h" |
| 50 | 51 |
| 51 namespace WebCore { | 52 namespace WebCore { |
| 52 | 53 |
| 53 static void initializeScriptWrappableForInterface(TestInterfacePython2* object) | 54 static void initializeScriptWrappableForInterface(TestInterfacePython2* object) |
| 54 { | 55 { |
| 55 if (ScriptWrappable::wrapperCanBeStoredInObject(object)) | 56 if (ScriptWrappable::wrapperCanBeStoredInObject(object)) |
| 56 ScriptWrappable::setTypeInfoInObject(object, &V8TestInterfacePython2::wr apperTypeInfo); | 57 ScriptWrappable::setTypeInfoInObject(object, &V8TestInterfacePython2::wr apperTypeInfo); |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 69 WebCore::initializeScriptWrappableForInterface(object); | 70 WebCore::initializeScriptWrappableForInterface(object); |
| 70 } | 71 } |
| 71 | 72 |
| 72 namespace WebCore { | 73 namespace WebCore { |
| 73 const WrapperTypeInfo V8TestInterfacePython2::wrapperTypeInfo = { gin::kEmbedder Blink, V8TestInterfacePython2::domTemplate, V8TestInterfacePython2::derefObject, 0, 0, V8TestInterfacePython2::visitDOMWrapper, V8TestInterfacePython2::installP erContextEnabledMethods, 0, WrapperTypeObjectPrototype, false }; | 74 const WrapperTypeInfo V8TestInterfacePython2::wrapperTypeInfo = { gin::kEmbedder Blink, V8TestInterfacePython2::domTemplate, V8TestInterfacePython2::derefObject, 0, 0, V8TestInterfacePython2::visitDOMWrapper, V8TestInterfacePython2::installP erContextEnabledMethods, 0, WrapperTypeObjectPrototype, false }; |
| 74 | 75 |
| 75 namespace TestInterfacePython2V8Internal { | 76 namespace TestInterfacePython2V8Internal { |
| 76 | 77 |
| 77 template <typename T> void V8_USE(T) { } | 78 template <typename T> void V8_USE(T) { } |
| 78 | 79 |
| 80 static void constructor(const v8::FunctionCallbackInfo<v8::Value>& info) | |
| 81 { | |
| 82 RefPtr<TestInterfacePython2> impl = TestInterfacePython2::create(); | |
| 83 v8::Handle<v8::Object> wrapper = info.Holder(); | |
| 84 | |
| 85 V8DOMWrapper::associateObjectWithWrapper<V8TestInterfacePython2>(impl.releas e(), &V8TestInterfacePython2::wrapperTypeInfo, wrapper, info.GetIsolate(), Wrapp erConfiguration::Dependent); | |
|
sof
2014/03/24 08:06:43
Shouldn't this be calling wrap()?
Nils Barth (inactive)
2014/03/24 08:55:27
Oh, good catch!
(Accidentally did for *named* cons
| |
| 86 v8SetReturnValue(info, wrapper); | |
| 87 } | |
| 88 | |
| 79 } // namespace TestInterfacePython2V8Internal | 89 } // namespace TestInterfacePython2V8Internal |
| 80 | 90 |
| 81 void V8TestInterfacePython2::visitDOMWrapper(void* object, const v8::Persistent< v8::Object>& wrapper, v8::Isolate* isolate) | 91 void V8TestInterfacePython2::visitDOMWrapper(void* object, const v8::Persistent< v8::Object>& wrapper, v8::Isolate* isolate) |
| 82 { | 92 { |
| 83 TestInterfacePython2* impl = fromInternalPointer(object); | 93 TestInterfacePython2* impl = fromInternalPointer(object); |
| 84 // The ownerNode() method may return a reference or a pointer. | 94 // The ownerNode() method may return a reference or a pointer. |
| 85 if (Node* owner = WTF::getPtr(impl->ownerNode())) { | 95 if (Node* owner = WTF::getPtr(impl->ownerNode())) { |
| 86 Node* root = V8GCController::opaqueRootForGC(owner, isolate); | 96 Node* root = V8GCController::opaqueRootForGC(owner, isolate); |
| 87 isolate->SetReferenceFromGroup(v8::UniqueId(reinterpret_cast<intptr_t>(r oot)), wrapper); | 97 isolate->SetReferenceFromGroup(v8::UniqueId(reinterpret_cast<intptr_t>(r oot)), wrapper); |
| 88 return; | 98 return; |
| 89 } | 99 } |
| 90 setObjectGroup(object, wrapper, isolate); | 100 setObjectGroup(object, wrapper, isolate); |
| 91 } | 101 } |
| 92 | 102 |
| 103 void V8TestInterfacePython2::constructorCallback(const v8::FunctionCallbackInfo< v8::Value>& info) | |
| 104 { | |
| 105 TRACE_EVENT_SCOPED_SAMPLING_STATE("Blink", "DOMConstructor"); | |
| 106 if (!info.IsConstructCall()) { | |
| 107 throwTypeError(ExceptionMessages::failedToConstruct("TestInterfacePython 2", "Please use the 'new' operator, this DOM object constructor cannot be called as a function."), info.GetIsolate()); | |
| 108 return; | |
| 109 } | |
| 110 | |
| 111 if (ConstructorMode::current() == ConstructorMode::WrapExistingObject) { | |
| 112 v8SetReturnValue(info, info.Holder()); | |
| 113 return; | |
| 114 } | |
| 115 | |
| 116 TestInterfacePython2V8Internal::constructor(info); | |
| 117 } | |
| 118 | |
| 93 static void configureV8TestInterfacePython2Template(v8::Handle<v8::FunctionTempl ate> functionTemplate, v8::Isolate* isolate) | 119 static void configureV8TestInterfacePython2Template(v8::Handle<v8::FunctionTempl ate> functionTemplate, v8::Isolate* isolate) |
| 94 { | 120 { |
| 95 functionTemplate->ReadOnlyPrototype(); | 121 functionTemplate->ReadOnlyPrototype(); |
| 96 | 122 |
| 97 v8::Local<v8::Signature> defaultSignature; | 123 v8::Local<v8::Signature> defaultSignature; |
| 98 defaultSignature = V8DOMConfiguration::installDOMClassTemplate(functionTempl ate, "TestInterfacePython2", v8::Local<v8::FunctionTemplate>(), V8TestInterfaceP ython2::internalFieldCount, | 124 defaultSignature = V8DOMConfiguration::installDOMClassTemplate(functionTempl ate, "TestInterfacePython2", v8::Local<v8::FunctionTemplate>(), V8TestInterfaceP ython2::internalFieldCount, |
| 99 0, 0, | 125 0, 0, |
| 100 0, 0, | 126 0, 0, |
| 101 0, 0, | 127 0, 0, |
| 102 isolate); | 128 isolate); |
| 129 functionTemplate->SetCallHandler(V8TestInterfacePython2::constructorCallback ); | |
| 130 functionTemplate->SetLength(0); | |
| 103 v8::Local<v8::ObjectTemplate> ALLOW_UNUSED instanceTemplate = functionTempla te->InstanceTemplate(); | 131 v8::Local<v8::ObjectTemplate> ALLOW_UNUSED instanceTemplate = functionTempla te->InstanceTemplate(); |
| 104 v8::Local<v8::ObjectTemplate> ALLOW_UNUSED prototypeTemplate = functionTempl ate->PrototypeTemplate(); | 132 v8::Local<v8::ObjectTemplate> ALLOW_UNUSED prototypeTemplate = functionTempl ate->PrototypeTemplate(); |
| 105 | 133 |
| 106 // Custom toString template | 134 // Custom toString template |
| 107 functionTemplate->Set(v8AtomicString(isolate, "toString"), V8PerIsolateData: :current()->toStringTemplate()); | 135 functionTemplate->Set(v8AtomicString(isolate, "toString"), V8PerIsolateData: :current()->toStringTemplate()); |
| 108 } | 136 } |
| 109 | 137 |
| 110 v8::Handle<v8::FunctionTemplate> V8TestInterfacePython2::domTemplate(v8::Isolate * isolate) | 138 v8::Handle<v8::FunctionTemplate> V8TestInterfacePython2::domTemplate(v8::Isolate * isolate) |
| 111 { | 139 { |
| 112 V8PerIsolateData* data = V8PerIsolateData::from(isolate); | 140 V8PerIsolateData* data = V8PerIsolateData::from(isolate); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 172 fromInternalPointer(object)->deref(); | 200 fromInternalPointer(object)->deref(); |
| 173 } | 201 } |
| 174 | 202 |
| 175 template<> | 203 template<> |
| 176 v8::Handle<v8::Value> toV8NoInline(TestInterfacePython2* impl, v8::Handle<v8::Ob ject> creationContext, v8::Isolate* isolate) | 204 v8::Handle<v8::Value> toV8NoInline(TestInterfacePython2* impl, v8::Handle<v8::Ob ject> creationContext, v8::Isolate* isolate) |
| 177 { | 205 { |
| 178 return toV8(impl, creationContext, isolate); | 206 return toV8(impl, creationContext, isolate); |
| 179 } | 207 } |
| 180 | 208 |
| 181 } // namespace WebCore | 209 } // namespace WebCore |
| OLD | NEW |