| 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 116 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 127         const char* const svalue; | 127         const char* const svalue; | 
| 128         ConstantType type; | 128         ConstantType type; | 
| 129     }; | 129     }; | 
| 130 | 130 | 
| 131     static void installConstants(v8::Handle<v8::FunctionTemplate>, v8::Handle<v8
     ::ObjectTemplate>, const ConstantConfiguration*, size_t constantCount, v8::Isola
     te*); | 131     static void installConstants(v8::Handle<v8::FunctionTemplate>, v8::Handle<v8
     ::ObjectTemplate>, const ConstantConfiguration*, size_t constantCount, v8::Isola
     te*); | 
| 132 | 132 | 
| 133     // MethodConfiguration translates into calls to Set() for setting up an | 133     // MethodConfiguration translates into calls to Set() for setting up an | 
| 134     // object's callbacks. It sets the method on both the FunctionTemplate or | 134     // object's callbacks. It sets the method on both the FunctionTemplate or | 
| 135     // the ObjectTemplate. | 135     // the ObjectTemplate. | 
| 136     struct MethodConfiguration { | 136     struct MethodConfiguration { | 
|  | 137         v8::Local<v8::Name> getName(v8::Isolate* isolate) const { return v8Atomi
     cString(isolate, name); } | 
|  | 138 | 
| 137         const char* const name; | 139         const char* const name; | 
| 138         v8::FunctionCallback callback; | 140         v8::FunctionCallback callback; | 
| 139         v8::FunctionCallback callbackForMainWorld; | 141         v8::FunctionCallback callbackForMainWorld; | 
| 140         int length; | 142         int length; | 
| 141         ExposeConfiguration exposeConfiguration; | 143         ExposeConfiguration exposeConfiguration; | 
| 142     }; | 144     }; | 
| 143 | 145 | 
|  | 146     struct SymbolKeyedMethodConfiguration { | 
|  | 147         v8::Local<v8::Name> getName(v8::Isolate* isolate) const { return getSymb
     ol(isolate); } | 
|  | 148 | 
|  | 149         v8::Local<v8::Symbol> (*getSymbol)(v8::Isolate*); | 
|  | 150         v8::FunctionCallback callback; | 
|  | 151         v8::FunctionCallback callbackForMainWorld; | 
|  | 152         int length; | 
|  | 153         ExposeConfiguration exposeConfiguration; | 
|  | 154     }; | 
|  | 155 | 
| 144     static void installMethods(v8::Handle<v8::ObjectTemplate>, v8::Handle<v8::Si
     gnature>, v8::PropertyAttribute, const MethodConfiguration*, size_t callbackCoun
     t, v8::Isolate*); | 156     static void installMethods(v8::Handle<v8::ObjectTemplate>, v8::Handle<v8::Si
     gnature>, v8::PropertyAttribute, const MethodConfiguration*, size_t callbackCoun
     t, v8::Isolate*); | 
| 145 | 157 | 
| 146     template <class Template> | 158     template <class ObjectOrTemplate, class Configuration> | 
| 147     static void installMethod(v8::Handle<Template> prototype, v8::Handle<v8::Sig
     nature> signature, v8::PropertyAttribute attribute, const MethodConfiguration& c
     allback, v8::Isolate* isolate) | 159     static void installMethod(v8::Handle<ObjectOrTemplate> objectOrTemplate, v8:
     :Handle<v8::Signature> signature, v8::PropertyAttribute attribute, const Configu
     ration& callback, v8::Isolate* isolate) | 
| 148     { | 160     { | 
| 149         DOMWrapperWorld& world = DOMWrapperWorld::current(isolate); | 161         DOMWrapperWorld& world = DOMWrapperWorld::current(isolate); | 
| 150         if (callback.exposeConfiguration == OnlyExposedToPrivateScript && !world
     .isPrivateScriptIsolatedWorld()) | 162         if (callback.exposeConfiguration == OnlyExposedToPrivateScript && !world
     .isPrivateScriptIsolatedWorld()) | 
| 151             return; | 163             return; | 
| 152 | 164 | 
| 153         v8::Local<v8::FunctionTemplate> functionTemplate = functionTemplateForMe
     thod(signature, callback, isolate); | 165         v8::Local<v8::FunctionTemplate> functionTemplate = functionTemplateForMe
     thod(signature, callback, isolate); | 
| 154         prototype->Set(v8AtomicString(isolate, callback.name), functionTemplate,
      attribute); | 166         setMethod(objectOrTemplate, callback.getName(isolate), functionTemplate,
      attribute); | 
| 155     } |  | 
| 156 |  | 
| 157     static void installMethod(v8::Handle<v8::Object> object, v8::Handle<v8::Sign
     ature> signature, v8::PropertyAttribute, const MethodConfiguration& callback, v8
     ::Isolate* isolate) |  | 
| 158     { |  | 
| 159         DOMWrapperWorld& world = DOMWrapperWorld::current(isolate); |  | 
| 160         if (callback.exposeConfiguration == OnlyExposedToPrivateScript && !world
     .isPrivateScriptIsolatedWorld()) |  | 
| 161             return; |  | 
| 162 |  | 
| 163         v8::Local<v8::FunctionTemplate> functionTemplate = functionTemplateForMe
     thod(signature, callback, isolate); |  | 
| 164         object->Set(v8AtomicString(isolate, callback.name), functionTemplate->Ge
     tFunction()); |  | 
| 165     } | 167     } | 
| 166 | 168 | 
| 167     static void installAccessors(v8::Handle<v8::ObjectTemplate>, v8::Handle<v8::
     Signature>, const AccessorConfiguration*, size_t accessorCount, v8::Isolate*); | 169     static void installAccessors(v8::Handle<v8::ObjectTemplate>, v8::Handle<v8::
     Signature>, const AccessorConfiguration*, size_t accessorCount, v8::Isolate*); | 
| 168 | 170 | 
| 169     static v8::Local<v8::Signature> installDOMClassTemplate(v8::Handle<v8::Funct
     ionTemplate>, const char* interfaceName, v8::Handle<v8::FunctionTemplate> parent
     Class, size_t fieldCount, | 171     static v8::Local<v8::Signature> installDOMClassTemplate(v8::Handle<v8::Funct
     ionTemplate>, const char* interfaceName, v8::Handle<v8::FunctionTemplate> parent
     Class, size_t fieldCount, | 
| 170         const AttributeConfiguration*, size_t attributeCount, | 172         const AttributeConfiguration*, size_t attributeCount, | 
| 171         const AccessorConfiguration*, size_t accessorCount, | 173         const AccessorConfiguration*, size_t accessorCount, | 
| 172         const MethodConfiguration*, size_t callbackCount, | 174         const MethodConfiguration*, size_t callbackCount, | 
| 173         v8::Isolate*); | 175         v8::Isolate*); | 
| 174 | 176 | 
| 175     static v8::Handle<v8::FunctionTemplate> domClassTemplate(v8::Isolate*, Wrapp
     erTypeInfo*, void (*)(v8::Handle<v8::FunctionTemplate>, v8::Isolate*)); | 177     static v8::Handle<v8::FunctionTemplate> domClassTemplate(v8::Isolate*, Wrapp
     erTypeInfo*, void (*)(v8::Handle<v8::FunctionTemplate>, v8::Isolate*)); | 
| 176 | 178 | 
| 177 private: | 179 private: | 
|  | 180     static void setMethod(v8::Handle<v8::Object> target, v8::Handle<v8::Name> na
     me, v8::Handle<v8::FunctionTemplate> functionTemplate, v8::PropertyAttribute att
     ribute) | 
|  | 181     { | 
|  | 182         target->Set(name, functionTemplate->GetFunction()); | 
|  | 183     } | 
|  | 184     static void setMethod(v8::Handle<v8::FunctionTemplate> target, v8::Handle<v8
     ::Name> name, v8::Handle<v8::FunctionTemplate> functionTemplate, v8::PropertyAtt
     ribute attribute) | 
|  | 185     { | 
|  | 186         target->Set(name, functionTemplate, attribute); | 
|  | 187     } | 
|  | 188     static void setMethod(v8::Handle<v8::ObjectTemplate> target, v8::Handle<v8::
     Name> name, v8::Handle<v8::FunctionTemplate> functionTemplate, v8::PropertyAttri
     bute attribute) | 
|  | 189     { | 
|  | 190         target->Set(name, functionTemplate, attribute); | 
|  | 191     } | 
|  | 192 | 
| 178     static v8::Handle<v8::FunctionTemplate> functionTemplateForMethod(v8::Handle
     <v8::Signature>, const MethodConfiguration&, v8::Isolate*); | 193     static v8::Handle<v8::FunctionTemplate> functionTemplateForMethod(v8::Handle
     <v8::Signature>, const MethodConfiguration&, v8::Isolate*); | 
|  | 194     static v8::Handle<v8::FunctionTemplate> functionTemplateForMethod(v8::Handle
     <v8::Signature>, const SymbolKeyedMethodConfiguration&, v8::Isolate*); | 
| 179 }; | 195 }; | 
| 180 | 196 | 
| 181 } // namespace blink | 197 } // namespace blink | 
| 182 | 198 | 
| 183 #endif // V8DOMConfiguration_h | 199 #endif // V8DOMConfiguration_h | 
| OLD | NEW | 
|---|