| 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(); |
| 41 WTF_MAKE_NONCOPYABLE(V8DOMConfiguration); |
| 40 public: | 42 public: |
| 41 // The following Configuration structs and install methods are used for | 43 // The following Configuration structs and install methods are used for |
| 42 // setting multiple properties on ObjectTemplate / FunctionTemplate, used | 44 // setting multiple properties on ObjectTemplate / FunctionTemplate, used |
| 43 // from the generated bindings initialization (ConfigureXXXTemplate). | 45 // from the generated bindings initialization (ConfigureXXXTemplate). |
| 44 // 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 |
| 45 // data table driven setup. | 47 // data table driven setup. |
| 46 | 48 |
| 47 enum ExposeConfiguration { | 49 enum ExposeConfiguration { |
| 48 ExposedToAllScripts, | 50 ExposedToAllScripts, |
| 49 OnlyExposedToPrivateScript, | 51 OnlyExposedToPrivateScript, |
| (...skipping 18 matching lines...) Expand all Loading... |
| 68 v8::AccessorNameGetterCallback getter; | 70 v8::AccessorNameGetterCallback getter; |
| 69 v8::AccessorNameSetterCallback setter; | 71 v8::AccessorNameSetterCallback setter; |
| 70 v8::AccessorNameGetterCallback getterForMainWorld; | 72 v8::AccessorNameGetterCallback getterForMainWorld; |
| 71 v8::AccessorNameSetterCallback setterForMainWorld; | 73 v8::AccessorNameSetterCallback setterForMainWorld; |
| 72 const WrapperTypeInfo* data; | 74 const WrapperTypeInfo* data; |
| 73 v8::AccessControl settings; | 75 v8::AccessControl settings; |
| 74 v8::PropertyAttribute attribute; | 76 v8::PropertyAttribute attribute; |
| 75 unsigned exposeConfiguration : 1; // ExposeConfiguration | 77 unsigned exposeConfiguration : 1; // ExposeConfiguration |
| 76 unsigned propertyLocationConfiguration : 3; // PropertyLocationConfigura
tion | 78 unsigned propertyLocationConfiguration : 3; // PropertyLocationConfigura
tion |
| 77 unsigned holderCheckConfiguration : 1; // HolderCheckConfiguration | 79 unsigned holderCheckConfiguration : 1; // HolderCheckConfiguration |
| 80 |
| 81 DISALLOW_ALLOCATION(); |
| 82 WTF_MAKE_NONCOPYABLE(AttributeConfiguration); |
| 78 }; | 83 }; |
| 79 | 84 |
| 80 static void installAttributes(v8::Isolate*, v8::Local<v8::ObjectTemplate> in
stanceTemplate, v8::Local<v8::ObjectTemplate> prototypeTemplate, const Attribute
Configuration*, size_t attributeCount); | 85 static void installAttributes(v8::Isolate*, v8::Local<v8::ObjectTemplate> in
stanceTemplate, v8::Local<v8::ObjectTemplate> prototypeTemplate, const Attribute
Configuration*, size_t attributeCount); |
| 81 | 86 |
| 82 static void installAttribute(v8::Isolate*, v8::Local<v8::ObjectTemplate> ins
tanceTemplate, v8::Local<v8::ObjectTemplate> prototypeTemplate, const AttributeC
onfiguration&); | 87 static void installAttribute(v8::Isolate*, v8::Local<v8::ObjectTemplate> ins
tanceTemplate, v8::Local<v8::ObjectTemplate> prototypeTemplate, const AttributeC
onfiguration&); |
| 83 | 88 |
| 84 // AccessorConfiguration translates into calls to SetAccessorProperty() | 89 // AccessorConfiguration translates into calls to SetAccessorProperty() |
| 85 // on prototype ObjectTemplate. | 90 // on prototype ObjectTemplate. |
| 86 struct AccessorConfiguration { | 91 struct AccessorConfiguration { |
| 87 const char* const name; | 92 const char* const name; |
| 88 v8::FunctionCallback getter; | 93 v8::FunctionCallback getter; |
| 89 v8::FunctionCallback setter; | 94 v8::FunctionCallback setter; |
| 90 v8::FunctionCallback getterForMainWorld; | 95 v8::FunctionCallback getterForMainWorld; |
| 91 v8::FunctionCallback setterForMainWorld; | 96 v8::FunctionCallback setterForMainWorld; |
| 92 const WrapperTypeInfo* data; | 97 const WrapperTypeInfo* data; |
| 93 v8::AccessControl settings; | 98 v8::AccessControl settings; |
| 94 v8::PropertyAttribute attribute; | 99 v8::PropertyAttribute attribute; |
| 95 unsigned exposeConfiguration : 1; // ExposeConfiguration | 100 unsigned exposeConfiguration : 1; // ExposeConfiguration |
| 96 unsigned propertyLocationConfiguration : 3; // PropertyLocationConfigura
tion | 101 unsigned propertyLocationConfiguration : 3; // PropertyLocationConfigura
tion |
| 97 unsigned holderCheckConfiguration : 1; // HolderCheckConfiguration | 102 unsigned holderCheckConfiguration : 1; // HolderCheckConfiguration |
| 103 |
| 104 DISALLOW_ALLOCATION(); |
| 105 WTF_MAKE_NONCOPYABLE(AccessorConfiguration); |
| 98 }; | 106 }; |
| 99 | 107 |
| 100 static void installAccessors(v8::Isolate*, v8::Local<v8::ObjectTemplate> ins
tanceTemplate, v8::Local<v8::ObjectTemplate> prototypeTemplate, v8::Local<v8::Fu
nctionTemplate> interfaceTemplate, v8::Local<v8::Signature>, const AccessorConfi
guration*, size_t accessorCount); | 108 static void installAccessors(v8::Isolate*, v8::Local<v8::ObjectTemplate> ins
tanceTemplate, v8::Local<v8::ObjectTemplate> prototypeTemplate, v8::Local<v8::Fu
nctionTemplate> interfaceTemplate, v8::Local<v8::Signature>, const AccessorConfi
guration*, size_t accessorCount); |
| 101 | 109 |
| 102 static void installAccessor(v8::Isolate*, v8::Local<v8::ObjectTemplate> inst
anceTemplate, v8::Local<v8::ObjectTemplate> prototypeTemplate, v8::Local<v8::Fun
ctionTemplate> interfaceTemplate, v8::Local<v8::Signature>, const AccessorConfig
uration&); | 110 static void installAccessor(v8::Isolate*, v8::Local<v8::ObjectTemplate> inst
anceTemplate, v8::Local<v8::ObjectTemplate> prototypeTemplate, v8::Local<v8::Fun
ctionTemplate> interfaceTemplate, v8::Local<v8::Signature>, const AccessorConfig
uration&); |
| 103 | 111 |
| 104 static void installAccessor(v8::Isolate*, v8::Local<v8::Object> instance, v8
::Local<v8::Object> prototype, v8::Local<v8::Function> interface, v8::Local<v8::
Signature>, const AccessorConfiguration&); | 112 static void installAccessor(v8::Isolate*, v8::Local<v8::Object> instance, v8
::Local<v8::Object> prototype, v8::Local<v8::Function> interface, v8::Local<v8::
Signature>, const AccessorConfiguration&); |
| 105 | 113 |
| 106 enum ConstantType { | 114 enum ConstantType { |
| 107 ConstantTypeShort, | 115 ConstantTypeShort, |
| 108 ConstantTypeLong, | 116 ConstantTypeLong, |
| 109 ConstantTypeUnsignedShort, | 117 ConstantTypeUnsignedShort, |
| 110 ConstantTypeUnsignedLong, | 118 ConstantTypeUnsignedLong, |
| 111 ConstantTypeFloat, | 119 ConstantTypeFloat, |
| 112 ConstantTypeDouble, | 120 ConstantTypeDouble, |
| 113 ConstantTypeString | 121 ConstantTypeString |
| 114 }; | 122 }; |
| 115 | 123 |
| 116 // ConstantConfiguration translates into calls to Set() for setting up an | 124 // ConstantConfiguration translates into calls to Set() for setting up an |
| 117 // object's constants. It sets the constant on both the FunctionTemplate and | 125 // object's constants. It sets the constant on both the FunctionTemplate and |
| 118 // the ObjectTemplate. PropertyAttributes is always ReadOnly. | 126 // the ObjectTemplate. PropertyAttributes is always ReadOnly. |
| 119 struct ConstantConfiguration { | 127 struct ConstantConfiguration { |
| 120 const char* const name; | 128 const char* const name; |
| 121 int ivalue; | 129 int ivalue; |
| 122 double dvalue; | 130 double dvalue; |
| 123 const char* const svalue; | 131 const char* const svalue; |
| 124 ConstantType type; | 132 ConstantType type; |
| 133 |
| 134 DISALLOW_ALLOCATION(); |
| 135 WTF_MAKE_NONCOPYABLE(ConstantConfiguration); |
| 125 }; | 136 }; |
| 126 | 137 |
| 127 // Constant installation | 138 // Constant installation |
| 128 // | 139 // |
| 129 // installConstants and installConstant are used for simple constants. They | 140 // installConstants and installConstant are used for simple constants. They |
| 130 // install constants using v8::Template::Set(), which results in a property | 141 // install constants using v8::Template::Set(), which results in a property |
| 131 // that is much faster to access from scripts. | 142 // that is much faster to access from scripts. |
| 132 // installConstantWithGetter is used when some C++ code needs to be executed | 143 // installConstantWithGetter is used when some C++ code needs to be executed |
| 133 // when the constant is accessed, e.g. to handle deprecation or measuring | 144 // when the constant is accessed, e.g. to handle deprecation or measuring |
| 134 // usage. The property appears the same to scripts, but is slower to access. | 145 // usage. The property appears the same to scripts, but is slower to access. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 146 v8::FunctionCallback callbackForWorld(const DOMWrapperWorld& world) cons
t | 157 v8::FunctionCallback callbackForWorld(const DOMWrapperWorld& world) cons
t |
| 147 { | 158 { |
| 148 return world.isMainWorld() && callbackForMainWorld ? callbackForMain
World : callback; | 159 return world.isMainWorld() && callbackForMainWorld ? callbackForMain
World : callback; |
| 149 } | 160 } |
| 150 | 161 |
| 151 const char* const name; | 162 const char* const name; |
| 152 v8::FunctionCallback callback; | 163 v8::FunctionCallback callback; |
| 153 v8::FunctionCallback callbackForMainWorld; | 164 v8::FunctionCallback callbackForMainWorld; |
| 154 int length; | 165 int length; |
| 155 ExposeConfiguration exposeConfiguration; | 166 ExposeConfiguration exposeConfiguration; |
| 167 |
| 168 DISALLOW_ALLOCATION(); |
| 169 WTF_MAKE_NONCOPYABLE(MethodConfiguration); |
| 156 }; | 170 }; |
| 157 | 171 |
| 158 struct SymbolKeyedMethodConfiguration { | 172 struct SymbolKeyedMethodConfiguration { |
| 159 v8::Local<v8::Name> methodName(v8::Isolate* isolate) const { return getS
ymbol(isolate); } | 173 v8::Local<v8::Name> methodName(v8::Isolate* isolate) const { return getS
ymbol(isolate); } |
| 160 v8::FunctionCallback callbackForWorld(const DOMWrapperWorld&) const | 174 v8::FunctionCallback callbackForWorld(const DOMWrapperWorld&) const |
| 161 { | 175 { |
| 162 return callback; | 176 return callback; |
| 163 } | 177 } |
| 164 | 178 |
| 165 v8::Local<v8::Symbol> (*getSymbol)(v8::Isolate*); | 179 v8::Local<v8::Symbol> (*getSymbol)(v8::Isolate*); |
| 166 v8::FunctionCallback callback; | 180 v8::FunctionCallback callback; |
| 167 // SymbolKeyedMethodConfiguration doesn't support per-world bindings. | 181 // SymbolKeyedMethodConfiguration doesn't support per-world bindings. |
| 168 int length; | 182 int length; |
| 169 ExposeConfiguration exposeConfiguration; | 183 ExposeConfiguration exposeConfiguration; |
| 184 |
| 185 DISALLOW_ALLOCATION(); |
| 186 WTF_MAKE_NONCOPYABLE(SymbolKeyedMethodConfiguration); |
| 170 }; | 187 }; |
| 171 | 188 |
| 172 static void installMethods(v8::Isolate*, v8::Local<v8::ObjectTemplate> proto
typeTemplate, v8::Local<v8::Signature>, v8::PropertyAttribute, const MethodConfi
guration*, size_t callbackCount); | 189 static void installMethods(v8::Isolate*, v8::Local<v8::ObjectTemplate> proto
typeTemplate, v8::Local<v8::Signature>, v8::PropertyAttribute, const MethodConfi
guration*, size_t callbackCount); |
| 173 | 190 |
| 174 static void installMethod(v8::Isolate*, v8::Local<v8::FunctionTemplate>, v8:
:Local<v8::Signature>, v8::PropertyAttribute, const MethodConfiguration&); | 191 static void installMethod(v8::Isolate*, v8::Local<v8::FunctionTemplate>, v8:
:Local<v8::Signature>, v8::PropertyAttribute, const MethodConfiguration&); |
| 175 | 192 |
| 176 static void installMethod(v8::Isolate*, v8::Local<v8::ObjectTemplate>, v8::L
ocal<v8::Signature>, v8::PropertyAttribute, const MethodConfiguration&); | 193 static void installMethod(v8::Isolate*, v8::Local<v8::ObjectTemplate>, v8::L
ocal<v8::Signature>, v8::PropertyAttribute, const MethodConfiguration&); |
| 177 | 194 |
| 178 static void installMethod(v8::Isolate*, v8::Local<v8::ObjectTemplate>, v8::L
ocal<v8::Signature>, v8::PropertyAttribute, const SymbolKeyedMethodConfiguration
&); | 195 static void installMethod(v8::Isolate*, v8::Local<v8::ObjectTemplate>, v8::L
ocal<v8::Signature>, v8::PropertyAttribute, const SymbolKeyedMethodConfiguration
&); |
| 179 | 196 |
| 180 static v8::Local<v8::Signature> installDOMClassTemplate(v8::Isolate*, v8::Lo
cal<v8::FunctionTemplate>, const char* interfaceName, v8::Local<v8::FunctionTemp
late> parentClass, size_t fieldCount, | 197 static v8::Local<v8::Signature> installDOMClassTemplate(v8::Isolate*, v8::Lo
cal<v8::FunctionTemplate>, const char* interfaceName, v8::Local<v8::FunctionTemp
late> parentClass, size_t fieldCount, |
| 181 const AttributeConfiguration*, size_t attributeCount, | 198 const AttributeConfiguration*, size_t attributeCount, |
| 182 const AccessorConfiguration*, size_t accessorCount, | 199 const AccessorConfiguration*, size_t accessorCount, |
| 183 const MethodConfiguration*, size_t callbackCount); | 200 const MethodConfiguration*, size_t callbackCount); |
| 184 | 201 |
| 185 static v8::Local<v8::FunctionTemplate> domClassTemplate(v8::Isolate*, Wrappe
rTypeInfo*, void (*)(v8::Local<v8::FunctionTemplate>, v8::Isolate*)); | 202 static v8::Local<v8::FunctionTemplate> domClassTemplate(v8::Isolate*, Wrappe
rTypeInfo*, void (*)(v8::Local<v8::FunctionTemplate>, v8::Isolate*)); |
| 186 }; | 203 }; |
| 187 | 204 |
| 188 } // namespace blink | 205 } // namespace blink |
| 189 | 206 |
| 190 #endif // V8DOMConfiguration_h | 207 #endif // V8DOMConfiguration_h |
| OLD | NEW |