Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(34)

Side by Side Diff: Source/bindings/v8/V8DOMConfiguration.cpp

Issue 176963017: Remove WrapperWorldType from V8 binding (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/bindings/v8/V8DOMConfiguration.h ('k') | Source/bindings/v8/V8DOMWrapper.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2012 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 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. 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 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 15 matching lines...) Expand all
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */ 27 */
28 28
29 #include "config.h" 29 #include "config.h"
30 #include "bindings/v8/V8DOMConfiguration.h" 30 #include "bindings/v8/V8DOMConfiguration.h"
31 31
32 #include "bindings/v8/V8Binding.h" 32 #include "bindings/v8/V8Binding.h"
33 33
34 namespace WebCore { 34 namespace WebCore {
35 35
36 void V8DOMConfiguration::installAttributes(v8::Handle<v8::ObjectTemplate> instan ceTemplate, v8::Handle<v8::ObjectTemplate> prototype, const AttributeConfigurati on* attributes, size_t attributeCount, v8::Isolate* isolate, WrapperWorldType cu rrentWorldType) 36 void V8DOMConfiguration::installAttributes(v8::Handle<v8::ObjectTemplate> instan ceTemplate, v8::Handle<v8::ObjectTemplate> prototype, const AttributeConfigurati on* attributes, size_t attributeCount, v8::Isolate* isolate)
37 { 37 {
38 for (size_t i = 0; i < attributeCount; ++i) 38 for (size_t i = 0; i < attributeCount; ++i)
39 installAttribute(instanceTemplate, prototype, attributes[i], isolate, cu rrentWorldType); 39 installAttribute(instanceTemplate, prototype, attributes[i], isolate);
40 } 40 }
41 41
42 void V8DOMConfiguration::installAccessors(v8::Handle<v8::ObjectTemplate> prototy pe, v8::Handle<v8::Signature> signature, const AccessorConfiguration* accessors, size_t accessorCount, v8::Isolate* isolate, WrapperWorldType currentWorldType) 42 void V8DOMConfiguration::installAccessors(v8::Handle<v8::ObjectTemplate> prototy pe, v8::Handle<v8::Signature> signature, const AccessorConfiguration* accessors, size_t accessorCount, v8::Isolate* isolate)
43 { 43 {
44 bool isMainWorld = DOMWrapperWorld::current(isolate)->isMainWorld();
44 for (size_t i = 0; i < accessorCount; ++i) { 45 for (size_t i = 0; i < accessorCount; ++i) {
45 v8::FunctionCallback getterCallback = accessors[i].getter; 46 v8::FunctionCallback getterCallback = accessors[i].getter;
46 v8::FunctionCallback setterCallback = accessors[i].setter; 47 v8::FunctionCallback setterCallback = accessors[i].setter;
47 if (currentWorldType == MainWorld) { 48 if (isMainWorld) {
48 if (accessors[i].getterForMainWorld) 49 if (accessors[i].getterForMainWorld)
49 getterCallback = accessors[i].getterForMainWorld; 50 getterCallback = accessors[i].getterForMainWorld;
50 if (accessors[i].setterForMainWorld) 51 if (accessors[i].setterForMainWorld)
51 setterCallback = accessors[i].setterForMainWorld; 52 setterCallback = accessors[i].setterForMainWorld;
52 } 53 }
53 54
54 v8::Local<v8::FunctionTemplate> getter; 55 v8::Local<v8::FunctionTemplate> getter;
55 if (getterCallback) { 56 if (getterCallback) {
56 getter = v8::FunctionTemplate::New(isolate, getterCallback, v8::Exte rnal::New(isolate, const_cast<WrapperTypeInfo*>(accessors[i].data)), signature, 0); 57 getter = v8::FunctionTemplate::New(isolate, getterCallback, v8::Exte rnal::New(isolate, const_cast<WrapperTypeInfo*>(accessors[i].data)), signature, 0);
57 getter->RemovePrototype(); 58 getter->RemovePrototype();
(...skipping 10 matching lines...) Expand all
68 void V8DOMConfiguration::installConstants(v8::Handle<v8::FunctionTemplate> funct ionDescriptor, v8::Handle<v8::ObjectTemplate> prototype, const ConstantConfigura tion* constants, size_t constantCount, v8::Isolate* isolate) 69 void V8DOMConfiguration::installConstants(v8::Handle<v8::FunctionTemplate> funct ionDescriptor, v8::Handle<v8::ObjectTemplate> prototype, const ConstantConfigura tion* constants, size_t constantCount, v8::Isolate* isolate)
69 { 70 {
70 for (size_t i = 0; i < constantCount; ++i) { 71 for (size_t i = 0; i < constantCount; ++i) {
71 const ConstantConfiguration* constant = &constants[i]; 72 const ConstantConfiguration* constant = &constants[i];
72 v8::Handle<v8::String> constantName = v8AtomicString(isolate, constant-> name); 73 v8::Handle<v8::String> constantName = v8AtomicString(isolate, constant-> name);
73 functionDescriptor->Set(constantName, v8::Integer::New(isolate, constant ->value), static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontDelete)); 74 functionDescriptor->Set(constantName, v8::Integer::New(isolate, constant ->value), static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontDelete));
74 prototype->Set(constantName, v8::Integer::New(isolate, constant->value), static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontDelete)); 75 prototype->Set(constantName, v8::Integer::New(isolate, constant->value), static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontDelete));
75 } 76 }
76 } 77 }
77 78
78 void V8DOMConfiguration::installCallbacks(v8::Handle<v8::ObjectTemplate> prototy pe, v8::Handle<v8::Signature> signature, v8::PropertyAttribute attributes, const MethodConfiguration* callbacks, size_t callbackCount, v8::Isolate* isolate, Wra pperWorldType currentWorldType) 79 void V8DOMConfiguration::installCallbacks(v8::Handle<v8::ObjectTemplate> prototy pe, v8::Handle<v8::Signature> signature, v8::PropertyAttribute attributes, const MethodConfiguration* callbacks, size_t callbackCount, v8::Isolate* isolate)
79 { 80 {
81 bool isMainWorld = DOMWrapperWorld::current(isolate)->isMainWorld();
80 for (size_t i = 0; i < callbackCount; ++i) { 82 for (size_t i = 0; i < callbackCount; ++i) {
81 v8::FunctionCallback callback = callbacks[i].callback; 83 v8::FunctionCallback callback = callbacks[i].callback;
82 if (currentWorldType == MainWorld && callbacks[i].callbackForMainWorld) 84 if (isMainWorld && callbacks[i].callbackForMainWorld)
83 callback = callbacks[i].callbackForMainWorld; 85 callback = callbacks[i].callbackForMainWorld;
84 v8::Local<v8::FunctionTemplate> functionTemplate = v8::FunctionTemplate: :New(isolate, callback, v8Undefined(), signature, callbacks[i].length); 86 v8::Local<v8::FunctionTemplate> functionTemplate = v8::FunctionTemplate: :New(isolate, callback, v8Undefined(), signature, callbacks[i].length);
85 functionTemplate->RemovePrototype(); 87 functionTemplate->RemovePrototype();
86 prototype->Set(v8AtomicString(isolate, callbacks[i].name), functionTempl ate, attributes); 88 prototype->Set(v8AtomicString(isolate, callbacks[i].name), functionTempl ate, attributes);
87 } 89 }
88 } 90 }
89 91
90 v8::Local<v8::Signature> V8DOMConfiguration::installDOMClassTemplate(v8::Handle< v8::FunctionTemplate> functionDescriptor, const char* interfaceName, v8::Handle< v8::FunctionTemplate> parentClass, size_t fieldCount, 92 v8::Local<v8::Signature> V8DOMConfiguration::installDOMClassTemplate(v8::Handle< v8::FunctionTemplate> functionDescriptor, const char* interfaceName, v8::Handle< v8::FunctionTemplate> parentClass, size_t fieldCount,
91 const AttributeConfiguration* attributes, size_t attributeCount, 93 const AttributeConfiguration* attributes, size_t attributeCount,
92 const AccessorConfiguration* accessors, size_t accessorCount, 94 const AccessorConfiguration* accessors, size_t accessorCount,
93 const MethodConfiguration* callbacks, size_t callbackCount, 95 const MethodConfiguration* callbacks, size_t callbackCount,
94 v8::Isolate* isolate, WrapperWorldType currentWorldType) 96 v8::Isolate* isolate)
95 { 97 {
96 functionDescriptor->SetClassName(v8AtomicString(isolate, interfaceName)); 98 functionDescriptor->SetClassName(v8AtomicString(isolate, interfaceName));
97 v8::Local<v8::ObjectTemplate> instanceTemplate = functionDescriptor->Instanc eTemplate(); 99 v8::Local<v8::ObjectTemplate> instanceTemplate = functionDescriptor->Instanc eTemplate();
98 instanceTemplate->SetInternalFieldCount(fieldCount); 100 instanceTemplate->SetInternalFieldCount(fieldCount);
99 if (!parentClass.IsEmpty()) { 101 if (!parentClass.IsEmpty()) {
100 functionDescriptor->Inherit(parentClass); 102 functionDescriptor->Inherit(parentClass);
101 // Marks the prototype object as one of native-backed objects. 103 // Marks the prototype object as one of native-backed objects.
102 // This is needed since bug 110436 asks WebKit to tell native-initiated prototypes from pure-JS ones. 104 // This is needed since bug 110436 asks WebKit to tell native-initiated prototypes from pure-JS ones.
103 // This doesn't mark kinds "root" classes like Node, where setting this changes prototype chain structure. 105 // This doesn't mark kinds "root" classes like Node, where setting this changes prototype chain structure.
104 v8::Local<v8::ObjectTemplate> prototype = functionDescriptor->PrototypeT emplate(); 106 v8::Local<v8::ObjectTemplate> prototype = functionDescriptor->PrototypeT emplate();
105 prototype->SetInternalFieldCount(v8PrototypeInternalFieldcount); 107 prototype->SetInternalFieldCount(v8PrototypeInternalFieldcount);
106 } 108 }
107 109
108 v8::Local<v8::Signature> defaultSignature = v8::Signature::New(isolate, func tionDescriptor); 110 v8::Local<v8::Signature> defaultSignature = v8::Signature::New(isolate, func tionDescriptor);
109 if (attributeCount) 111 if (attributeCount)
110 installAttributes(instanceTemplate, functionDescriptor->PrototypeTemplat e(), attributes, attributeCount, isolate, currentWorldType); 112 installAttributes(instanceTemplate, functionDescriptor->PrototypeTemplat e(), attributes, attributeCount, isolate);
111 if (accessorCount) 113 if (accessorCount)
112 installAccessors(functionDescriptor->PrototypeTemplate(), defaultSignatu re, accessors, accessorCount, isolate, currentWorldType); 114 installAccessors(functionDescriptor->PrototypeTemplate(), defaultSignatu re, accessors, accessorCount, isolate);
113 if (callbackCount) 115 if (callbackCount)
114 installCallbacks(functionDescriptor->PrototypeTemplate(), defaultSignatu re, static_cast<v8::PropertyAttribute>(v8::DontDelete), callbacks, callbackCount , isolate, currentWorldType); 116 installCallbacks(functionDescriptor->PrototypeTemplate(), defaultSignatu re, static_cast<v8::PropertyAttribute>(v8::DontDelete), callbacks, callbackCount , isolate);
115 return defaultSignature; 117 return defaultSignature;
116 } 118 }
117 119
118 } // namespace WebCore 120 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/bindings/v8/V8DOMConfiguration.h ('k') | Source/bindings/v8/V8DOMWrapper.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698