Chromium Code Reviews| 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 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 170 DOMWrapperWorld& world = DOMWrapperWorld::current(isolate); | 170 DOMWrapperWorld& world = DOMWrapperWorld::current(isolate); |
| 171 if (callback.exposeConfiguration == OnlyExposedToPrivateScript && !world .isPrivateScriptIsolatedWorld()) | 171 if (callback.exposeConfiguration == OnlyExposedToPrivateScript && !world .isPrivateScriptIsolatedWorld()) |
| 172 return; | 172 return; |
| 173 | 173 |
| 174 v8::Local<v8::FunctionTemplate> functionTemplate = functionTemplateForCa llback(isolate, signature, callback.callbackForWorld(world), callback.length); | 174 v8::Local<v8::FunctionTemplate> functionTemplate = functionTemplateForCa llback(isolate, signature, callback.callbackForWorld(world), callback.length); |
| 175 setMethod(objectOrTemplate, callback.methodName(isolate), functionTempla te, attribute); | 175 setMethod(objectOrTemplate, callback.methodName(isolate), functionTempla te, attribute); |
| 176 } | 176 } |
| 177 | 177 |
| 178 static void installAccessors(v8::Isolate*, v8::Handle<v8::ObjectTemplate>, v 8::Handle<v8::Signature>, const AccessorConfiguration*, size_t accessorCount); | 178 static void installAccessors(v8::Isolate*, v8::Handle<v8::ObjectTemplate>, v 8::Handle<v8::Signature>, const AccessorConfiguration*, size_t accessorCount); |
| 179 | 179 |
| 180 template<class ObjectOrTemplate> | |
| 181 static inline void installAccessor(v8::Handle<ObjectOrTemplate> instanceTemp late, v8::Handle<ObjectOrTemplate> prototype, v8::Handle<v8::Signature> signatur e, const AccessorConfiguration& accessor, v8::Isolate* isolate) | |
|
haraken
2015/02/13 15:08:24
We might not want to duplicate the code between in
Yuki
2015/02/16 10:51:51
Refactored the code a bit.
Since it seemed that ge
| |
| 182 { | |
| 183 DOMWrapperWorld& world = DOMWrapperWorld::current(isolate); | |
| 184 if (accessor.exposeConfiguration == OnlyExposedToPrivateScript && !world .isPrivateScriptIsolatedWorld()) | |
| 185 return; | |
| 186 | |
| 187 v8::FunctionCallback getterCallback = accessor.getter; | |
| 188 v8::FunctionCallback setterCallback = accessor.setter; | |
| 189 if (world.isMainWorld()) { | |
| 190 if (accessor.getterForMainWorld) | |
| 191 getterCallback = accessor.getterForMainWorld; | |
| 192 if (accessor.setterForMainWorld) | |
| 193 setterCallback = accessor.setterForMainWorld; | |
| 194 } | |
| 195 v8::Local<v8::FunctionTemplate> getter; | |
| 196 if (getterCallback) { | |
| 197 getter = v8::FunctionTemplate::New(isolate, getterCallback, v8::Exte rnal::New(isolate, const_cast<WrapperTypeInfo*>(accessor.data)), signature, 0); | |
| 198 getter->RemovePrototype(); | |
| 199 } | |
| 200 v8::Local<v8::FunctionTemplate> setter; | |
| 201 if (setterCallback) { | |
| 202 setter = v8::FunctionTemplate::New(isolate, setterCallback, v8::Exte rnal::New(isolate, const_cast<WrapperTypeInfo*>(accessor.data)), signature, 1); | |
| 203 setter->RemovePrototype(); | |
| 204 } | |
| 205 prototype->SetAccessorProperty(v8AtomicString(isolate, accessor.name), g etter, setter, accessor.attribute, accessor.settings); | |
| 206 } | |
| 207 | |
| 180 static v8::Local<v8::Signature> installDOMClassTemplate(v8::Isolate*, v8::Lo cal<v8::FunctionTemplate>, const char* interfaceName, v8::Handle<v8::FunctionTem plate> parentClass, size_t fieldCount, | 208 static v8::Local<v8::Signature> installDOMClassTemplate(v8::Isolate*, v8::Lo cal<v8::FunctionTemplate>, const char* interfaceName, v8::Handle<v8::FunctionTem plate> parentClass, size_t fieldCount, |
| 181 const AttributeConfiguration*, size_t attributeCount, | 209 const AttributeConfiguration*, size_t attributeCount, |
| 182 const AccessorConfiguration*, size_t accessorCount, | 210 const AccessorConfiguration*, size_t accessorCount, |
| 183 const MethodConfiguration*, size_t callbackCount); | 211 const MethodConfiguration*, size_t callbackCount); |
| 184 | 212 |
| 185 static v8::Handle<v8::FunctionTemplate> domClassTemplate(v8::Isolate*, Wrapp erTypeInfo*, void (*)(v8::Local<v8::FunctionTemplate>, v8::Isolate*)); | 213 static v8::Handle<v8::FunctionTemplate> domClassTemplate(v8::Isolate*, Wrapp erTypeInfo*, void (*)(v8::Local<v8::FunctionTemplate>, v8::Isolate*)); |
| 186 | 214 |
| 187 private: | 215 private: |
| 188 static void setMethod(v8::Handle<v8::Object> target, v8::Handle<v8::Name> na me, v8::Handle<v8::FunctionTemplate> functionTemplate, v8::PropertyAttribute att ribute) | 216 static void setMethod(v8::Handle<v8::Object> target, v8::Handle<v8::Name> na me, v8::Handle<v8::FunctionTemplate> functionTemplate, v8::PropertyAttribute att ribute) |
| 189 { | 217 { |
| 190 target->Set(name, functionTemplate->GetFunction()); | 218 target->Set(name, functionTemplate->GetFunction()); |
| 191 } | 219 } |
| 192 static void setMethod(v8::Handle<v8::FunctionTemplate> target, v8::Handle<v8 ::Name> name, v8::Handle<v8::FunctionTemplate> functionTemplate, v8::PropertyAtt ribute attribute) | 220 static void setMethod(v8::Handle<v8::FunctionTemplate> target, v8::Handle<v8 ::Name> name, v8::Handle<v8::FunctionTemplate> functionTemplate, v8::PropertyAtt ribute attribute) |
| 193 { | 221 { |
| 194 target->Set(name, functionTemplate, attribute); | 222 target->Set(name, functionTemplate, attribute); |
| 195 } | 223 } |
| 196 static void setMethod(v8::Handle<v8::ObjectTemplate> target, v8::Handle<v8:: Name> name, v8::Handle<v8::FunctionTemplate> functionTemplate, v8::PropertyAttri bute attribute) | 224 static void setMethod(v8::Handle<v8::ObjectTemplate> target, v8::Handle<v8:: Name> name, v8::Handle<v8::FunctionTemplate> functionTemplate, v8::PropertyAttri bute attribute) |
| 197 { | 225 { |
| 198 target->Set(name, functionTemplate, attribute); | 226 target->Set(name, functionTemplate, attribute); |
| 199 } | 227 } |
| 200 | 228 |
| 201 static v8::Handle<v8::FunctionTemplate> functionTemplateForCallback(v8::Isol ate*, v8::Handle<v8::Signature>, v8::FunctionCallback, int length); | 229 static v8::Handle<v8::FunctionTemplate> functionTemplateForCallback(v8::Isol ate*, v8::Handle<v8::Signature>, v8::FunctionCallback, int length); |
| 202 }; | 230 }; |
| 203 | 231 |
| 204 } // namespace blink | 232 } // namespace blink |
| 205 | 233 |
| 206 #endif // V8DOMConfiguration_h | 234 #endif // V8DOMConfiguration_h |
| OLD | NEW |