OLD | NEW |
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 19 matching lines...) Expand all Loading... |
30 #define V8DOMConfiguration_h | 30 #define V8DOMConfiguration_h |
31 | 31 |
32 #include "bindings/core/v8/V8Binding.h" | 32 #include "bindings/core/v8/V8Binding.h" |
33 #include "bindings/core/v8/V8DOMWrapper.h" | 33 #include "bindings/core/v8/V8DOMWrapper.h" |
34 #include "core/CoreExport.h" | 34 #include "core/CoreExport.h" |
35 #include <v8.h> | 35 #include <v8.h> |
36 | 36 |
37 namespace blink { | 37 namespace blink { |
38 | 38 |
39 class CORE_EXPORT V8DOMConfiguration final { | 39 class CORE_EXPORT V8DOMConfiguration final { |
40 DISALLOW_ALLOCATION(); | 40 DISALLOW_NEW(); |
41 WTF_MAKE_NONCOPYABLE(V8DOMConfiguration); | 41 WTF_MAKE_NONCOPYABLE(V8DOMConfiguration); |
42 public: | 42 public: |
43 // The following Configuration structs and install methods are used for | 43 // The following Configuration structs and install methods are used for |
44 // setting multiple properties on ObjectTemplate / FunctionTemplate, used | 44 // setting multiple properties on ObjectTemplate / FunctionTemplate, used |
45 // from the generated bindings initialization (ConfigureXXXTemplate). | 45 // from the generated bindings initialization (ConfigureXXXTemplate). |
46 // This greatly reduces the binary size by moving from code driven setup to | 46 // This greatly reduces the binary size by moving from code driven setup to |
47 // data table driven setup. | 47 // data table driven setup. |
48 | 48 |
49 enum ExposeConfiguration { | 49 enum ExposeConfiguration { |
50 ExposedToAllScripts, | 50 ExposedToAllScripts, |
51 OnlyExposedToPrivateScript, | 51 OnlyExposedToPrivateScript, |
52 }; | 52 }; |
53 | 53 |
54 // Bitflags to show where the member will be defined. | 54 // Bitflags to show where the member will be defined. |
55 enum PropertyLocationConfiguration { | 55 enum PropertyLocationConfiguration { |
56 OnInstance = 1 << 0, | 56 OnInstance = 1 << 0, |
57 OnPrototype = 1 << 1, | 57 OnPrototype = 1 << 1, |
58 OnInterface = 1 << 2, | 58 OnInterface = 1 << 2, |
59 }; | 59 }; |
60 | 60 |
61 enum HolderCheckConfiguration { | 61 enum HolderCheckConfiguration { |
62 CheckHolder, | 62 CheckHolder, |
63 DoNotCheckHolder, | 63 DoNotCheckHolder, |
64 }; | 64 }; |
65 | 65 |
66 // AttributeConfiguration translates into calls to SetAccessor() on either | 66 // AttributeConfiguration translates into calls to SetAccessor() on either |
67 // the instance or the prototype ObjectTemplate, based on |instanceOrPrototy
peConfiguration|. | 67 // the instance or the prototype ObjectTemplate, based on |instanceOrPrototy
peConfiguration|. |
68 struct AttributeConfiguration { | 68 struct AttributeConfiguration { |
69 AttributeConfiguration& operator=(const AttributeConfiguration&) = delet
e; | 69 AttributeConfiguration& operator=(const AttributeConfiguration&) = delet
e; |
70 DISALLOW_ALLOCATION(); | 70 DISALLOW_NEW(); |
71 const char* const name; | 71 const char* const name; |
72 v8::AccessorNameGetterCallback getter; | 72 v8::AccessorNameGetterCallback getter; |
73 v8::AccessorNameSetterCallback setter; | 73 v8::AccessorNameSetterCallback setter; |
74 v8::AccessorNameGetterCallback getterForMainWorld; | 74 v8::AccessorNameGetterCallback getterForMainWorld; |
75 v8::AccessorNameSetterCallback setterForMainWorld; | 75 v8::AccessorNameSetterCallback setterForMainWorld; |
76 const WrapperTypeInfo* data; | 76 const WrapperTypeInfo* data; |
77 unsigned settings : 8; // v8::AccessControl | 77 unsigned settings : 8; // v8::AccessControl |
78 unsigned attribute : 8; // v8::PropertyAttribute | 78 unsigned attribute : 8; // v8::PropertyAttribute |
79 unsigned exposeConfiguration : 1; // ExposeConfiguration | 79 unsigned exposeConfiguration : 1; // ExposeConfiguration |
80 unsigned propertyLocationConfiguration : 3; // PropertyLocationConfigura
tion | 80 unsigned propertyLocationConfiguration : 3; // PropertyLocationConfigura
tion |
81 unsigned holderCheckConfiguration : 1; // HolderCheckConfiguration | 81 unsigned holderCheckConfiguration : 1; // HolderCheckConfiguration |
82 }; | 82 }; |
83 | 83 |
84 static void installAttributes(v8::Isolate*, v8::Local<v8::ObjectTemplate> in
stanceTemplate, v8::Local<v8::ObjectTemplate> prototypeTemplate, const Attribute
Configuration*, size_t attributeCount); | 84 static void installAttributes(v8::Isolate*, v8::Local<v8::ObjectTemplate> in
stanceTemplate, v8::Local<v8::ObjectTemplate> prototypeTemplate, const Attribute
Configuration*, size_t attributeCount); |
85 | 85 |
86 static void installAttribute(v8::Isolate*, v8::Local<v8::ObjectTemplate> ins
tanceTemplate, v8::Local<v8::ObjectTemplate> prototypeTemplate, const AttributeC
onfiguration&); | 86 static void installAttribute(v8::Isolate*, v8::Local<v8::ObjectTemplate> ins
tanceTemplate, v8::Local<v8::ObjectTemplate> prototypeTemplate, const AttributeC
onfiguration&); |
87 | 87 |
88 // AccessorConfiguration translates into calls to SetAccessorProperty() | 88 // AccessorConfiguration translates into calls to SetAccessorProperty() |
89 // on prototype ObjectTemplate. | 89 // on prototype ObjectTemplate. |
90 struct AccessorConfiguration { | 90 struct AccessorConfiguration { |
91 AccessorConfiguration& operator=(const AccessorConfiguration&) = delete; | 91 AccessorConfiguration& operator=(const AccessorConfiguration&) = delete; |
92 DISALLOW_ALLOCATION(); | 92 DISALLOW_NEW(); |
93 const char* const name; | 93 const char* const name; |
94 v8::FunctionCallback getter; | 94 v8::FunctionCallback getter; |
95 v8::FunctionCallback setter; | 95 v8::FunctionCallback setter; |
96 v8::FunctionCallback getterForMainWorld; | 96 v8::FunctionCallback getterForMainWorld; |
97 v8::FunctionCallback setterForMainWorld; | 97 v8::FunctionCallback setterForMainWorld; |
98 const WrapperTypeInfo* data; | 98 const WrapperTypeInfo* data; |
99 unsigned settings : 8; // v8::AccessControl | 99 unsigned settings : 8; // v8::AccessControl |
100 unsigned attribute : 8; // v8::PropertyAttribute | 100 unsigned attribute : 8; // v8::PropertyAttribute |
101 unsigned exposeConfiguration : 1; // ExposeConfiguration | 101 unsigned exposeConfiguration : 1; // ExposeConfiguration |
102 unsigned propertyLocationConfiguration : 3; // PropertyLocationConfigura
tion | 102 unsigned propertyLocationConfiguration : 3; // PropertyLocationConfigura
tion |
(...skipping 13 matching lines...) Expand all Loading... |
116 ConstantTypeUnsignedLong, | 116 ConstantTypeUnsignedLong, |
117 ConstantTypeFloat, | 117 ConstantTypeFloat, |
118 ConstantTypeDouble | 118 ConstantTypeDouble |
119 }; | 119 }; |
120 | 120 |
121 // ConstantConfiguration translates into calls to Set() for setting up an | 121 // ConstantConfiguration translates into calls to Set() for setting up an |
122 // object's constants. It sets the constant on both the FunctionTemplate and | 122 // object's constants. It sets the constant on both the FunctionTemplate and |
123 // the ObjectTemplate. PropertyAttributes is always ReadOnly. | 123 // the ObjectTemplate. PropertyAttributes is always ReadOnly. |
124 struct ConstantConfiguration { | 124 struct ConstantConfiguration { |
125 ConstantConfiguration& operator=(const ConstantConfiguration&) = delete; | 125 ConstantConfiguration& operator=(const ConstantConfiguration&) = delete; |
126 DISALLOW_ALLOCATION(); | 126 DISALLOW_NEW(); |
127 const char* const name; | 127 const char* const name; |
128 int ivalue; | 128 int ivalue; |
129 double dvalue; | 129 double dvalue; |
130 ConstantType type; | 130 ConstantType type; |
131 }; | 131 }; |
132 | 132 |
133 // Constant installation | 133 // Constant installation |
134 // | 134 // |
135 // installConstants and installConstant are used for simple constants. They | 135 // installConstants and installConstant are used for simple constants. They |
136 // install constants using v8::Template::Set(), which results in a property | 136 // install constants using v8::Template::Set(), which results in a property |
137 // that is much faster to access from scripts. | 137 // that is much faster to access from scripts. |
138 // installConstantWithGetter is used when some C++ code needs to be executed | 138 // installConstantWithGetter is used when some C++ code needs to be executed |
139 // when the constant is accessed, e.g. to handle deprecation or measuring | 139 // when the constant is accessed, e.g. to handle deprecation or measuring |
140 // usage. The property appears the same to scripts, but is slower to access. | 140 // usage. The property appears the same to scripts, but is slower to access. |
141 static void installConstants(v8::Isolate*, v8::Local<v8::FunctionTemplate> f
unctionDescriptor, v8::Local<v8::ObjectTemplate> prototypeTemplate, const Consta
ntConfiguration*, size_t constantCount); | 141 static void installConstants(v8::Isolate*, v8::Local<v8::FunctionTemplate> f
unctionDescriptor, v8::Local<v8::ObjectTemplate> prototypeTemplate, const Consta
ntConfiguration*, size_t constantCount); |
142 | 142 |
143 static void installConstant(v8::Isolate*, v8::Local<v8::FunctionTemplate> fu
nctionDescriptor, v8::Local<v8::ObjectTemplate> prototypeTemplate, const Constan
tConfiguration&); | 143 static void installConstant(v8::Isolate*, v8::Local<v8::FunctionTemplate> fu
nctionDescriptor, v8::Local<v8::ObjectTemplate> prototypeTemplate, const Constan
tConfiguration&); |
144 | 144 |
145 static void installConstantWithGetter(v8::Isolate*, v8::Local<v8::FunctionTe
mplate> functionDescriptor, v8::Local<v8::ObjectTemplate> prototypeTemplate, con
st char* name, v8::AccessorNameGetterCallback); | 145 static void installConstantWithGetter(v8::Isolate*, v8::Local<v8::FunctionTe
mplate> functionDescriptor, v8::Local<v8::ObjectTemplate> prototypeTemplate, con
st char* name, v8::AccessorNameGetterCallback); |
146 | 146 |
147 // MethodConfiguration translates into calls to Set() for setting up an | 147 // MethodConfiguration translates into calls to Set() for setting up an |
148 // object's callbacks. It sets the method on both the FunctionTemplate or | 148 // object's callbacks. It sets the method on both the FunctionTemplate or |
149 // the ObjectTemplate. | 149 // the ObjectTemplate. |
150 struct MethodConfiguration { | 150 struct MethodConfiguration { |
151 MethodConfiguration& operator=(const MethodConfiguration&) = delete; | 151 MethodConfiguration& operator=(const MethodConfiguration&) = delete; |
152 DISALLOW_ALLOCATION(); | 152 DISALLOW_NEW(); |
153 v8::Local<v8::Name> methodName(v8::Isolate* isolate) const { return v8At
omicString(isolate, name); } | 153 v8::Local<v8::Name> methodName(v8::Isolate* isolate) const { return v8At
omicString(isolate, name); } |
154 v8::FunctionCallback callbackForWorld(const DOMWrapperWorld& world) cons
t | 154 v8::FunctionCallback callbackForWorld(const DOMWrapperWorld& world) cons
t |
155 { | 155 { |
156 return world.isMainWorld() && callbackForMainWorld ? callbackForMain
World : callback; | 156 return world.isMainWorld() && callbackForMainWorld ? callbackForMain
World : callback; |
157 } | 157 } |
158 | 158 |
159 const char* const name; | 159 const char* const name; |
160 v8::FunctionCallback callback; | 160 v8::FunctionCallback callback; |
161 v8::FunctionCallback callbackForMainWorld; | 161 v8::FunctionCallback callbackForMainWorld; |
162 int length; | 162 int length; |
163 unsigned attribute : 8; // v8::PropertyAttribute | 163 unsigned attribute : 8; // v8::PropertyAttribute |
164 unsigned exposeConfiguration : 1; // ExposeConfiguration | 164 unsigned exposeConfiguration : 1; // ExposeConfiguration |
165 unsigned propertyLocationConfiguration : 3; // PropertyLocationConfigura
tion | 165 unsigned propertyLocationConfiguration : 3; // PropertyLocationConfigura
tion |
166 }; | 166 }; |
167 | 167 |
168 struct SymbolKeyedMethodConfiguration { | 168 struct SymbolKeyedMethodConfiguration { |
169 SymbolKeyedMethodConfiguration& operator=(const SymbolKeyedMethodConfigu
ration&) = delete; | 169 SymbolKeyedMethodConfiguration& operator=(const SymbolKeyedMethodConfigu
ration&) = delete; |
170 DISALLOW_ALLOCATION(); | 170 DISALLOW_NEW(); |
171 v8::Local<v8::Name> methodName(v8::Isolate* isolate) const { return getS
ymbol(isolate); } | 171 v8::Local<v8::Name> methodName(v8::Isolate* isolate) const { return getS
ymbol(isolate); } |
172 v8::FunctionCallback callbackForWorld(const DOMWrapperWorld&) const | 172 v8::FunctionCallback callbackForWorld(const DOMWrapperWorld&) const |
173 { | 173 { |
174 return callback; | 174 return callback; |
175 } | 175 } |
176 | 176 |
177 v8::Local<v8::Symbol> (*getSymbol)(v8::Isolate*); | 177 v8::Local<v8::Symbol> (*getSymbol)(v8::Isolate*); |
178 v8::FunctionCallback callback; | 178 v8::FunctionCallback callback; |
179 // SymbolKeyedMethodConfiguration doesn't support per-world bindings. | 179 // SymbolKeyedMethodConfiguration doesn't support per-world bindings. |
180 int length; | 180 int length; |
(...skipping 14 matching lines...) Expand all Loading... |
195 const AttributeConfiguration*, size_t attributeCount, | 195 const AttributeConfiguration*, size_t attributeCount, |
196 const AccessorConfiguration*, size_t accessorCount, | 196 const AccessorConfiguration*, size_t accessorCount, |
197 const MethodConfiguration*, size_t methodCount); | 197 const MethodConfiguration*, size_t methodCount); |
198 | 198 |
199 static v8::Local<v8::FunctionTemplate> domClassTemplate(v8::Isolate*, Wrappe
rTypeInfo*, void (*)(v8::Local<v8::FunctionTemplate>, v8::Isolate*)); | 199 static v8::Local<v8::FunctionTemplate> domClassTemplate(v8::Isolate*, Wrappe
rTypeInfo*, void (*)(v8::Local<v8::FunctionTemplate>, v8::Isolate*)); |
200 }; | 200 }; |
201 | 201 |
202 } // namespace blink | 202 } // namespace blink |
203 | 203 |
204 #endif // V8DOMConfiguration_h | 204 #endif // V8DOMConfiguration_h |
OLD | NEW |