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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 // driven setup. | 43 // driven setup. |
44 | 44 |
45 // AttributeConfiguration translates into calls to SetAccessor() on either | 45 // AttributeConfiguration translates into calls to SetAccessor() on either |
46 // the instance or the prototype ObjectTemplate, based on |onPrototype|. | 46 // the instance or the prototype ObjectTemplate, based on |onPrototype|. |
47 struct AttributeConfiguration { | 47 struct AttributeConfiguration { |
48 const char* const name; | 48 const char* const name; |
49 v8::AccessorGetterCallback getter; | 49 v8::AccessorGetterCallback getter; |
50 v8::AccessorSetterCallback setter; | 50 v8::AccessorSetterCallback setter; |
51 v8::AccessorGetterCallback getterForMainWorld; | 51 v8::AccessorGetterCallback getterForMainWorld; |
52 v8::AccessorSetterCallback setterForMainWorld; | 52 v8::AccessorSetterCallback setterForMainWorld; |
53 WrapperTypeInfo* data; | 53 const WrapperTypeInfo* data; |
54 v8::AccessControl settings; | 54 v8::AccessControl settings; |
55 v8::PropertyAttribute attribute; | 55 v8::PropertyAttribute attribute; |
56 bool onPrototype; | 56 bool onPrototype; |
57 }; | 57 }; |
58 | 58 |
59 static void installAttributes(v8::Handle<v8::ObjectTemplate>, v8::Handle<v8:
:ObjectTemplate>, const AttributeConfiguration*, size_t attributeCount, v8::Isol
ate*, WrapperWorldType currentWorldType); | 59 static void installAttributes(v8::Handle<v8::ObjectTemplate>, v8::Handle<v8:
:ObjectTemplate>, const AttributeConfiguration*, size_t attributeCount, v8::Isol
ate*, WrapperWorldType currentWorldType); |
60 | 60 |
61 template<class ObjectOrTemplate> | 61 template<class ObjectOrTemplate> |
62 static inline void installAttribute(v8::Handle<ObjectOrTemplate> instance, v
8::Handle<ObjectOrTemplate> prototype, const AttributeConfiguration& attribute,
v8::Isolate*) | 62 static inline void installAttribute(v8::Handle<ObjectOrTemplate> instance, v
8::Handle<ObjectOrTemplate> prototype, const AttributeConfiguration& attribute,
v8::Isolate*) |
63 { | 63 { |
64 (attribute.onPrototype ? prototype : instance)->SetAccessor(v8::String::
NewSymbol(attribute.name), | 64 (attribute.onPrototype ? prototype : instance)->SetAccessor(v8::String::
NewSymbol(attribute.name), |
65 attribute.ge
tter, | 65 attribute.ge
tter, |
66 attribute.se
tter, | 66 attribute.se
tter, |
67 v8::External
::New(attribute.data), | 67 v8::External
::New(const_cast<WrapperTypeInfo*>(attribute.data)), |
68 attribute.se
ttings, | 68 attribute.se
ttings, |
69 attribute.at
tribute); | 69 attribute.at
tribute); |
70 } | 70 } |
71 | 71 |
72 template<class ObjectOrTemplate> | 72 template<class ObjectOrTemplate> |
73 static inline void installAttribute(v8::Handle<ObjectOrTemplate> instance, v
8::Handle<ObjectOrTemplate> prototype, const AttributeConfiguration& attribute,
v8::Isolate*, WrapperWorldType currentWorldType) | 73 static inline void installAttribute(v8::Handle<ObjectOrTemplate> instance, v
8::Handle<ObjectOrTemplate> prototype, const AttributeConfiguration& attribute,
v8::Isolate*, WrapperWorldType currentWorldType) |
74 { | 74 { |
75 v8::AccessorGetterCallback getter = attribute.getter; | 75 v8::AccessorGetterCallback getter = attribute.getter; |
76 v8::AccessorSetterCallback setter = attribute.setter; | 76 v8::AccessorSetterCallback setter = attribute.setter; |
77 if (currentWorldType == MainWorld) { | 77 if (currentWorldType == MainWorld) { |
78 if (attribute.getterForMainWorld) | 78 if (attribute.getterForMainWorld) |
79 getter = attribute.getterForMainWorld; | 79 getter = attribute.getterForMainWorld; |
80 if (attribute.setterForMainWorld) | 80 if (attribute.setterForMainWorld) |
81 setter = attribute.setterForMainWorld; | 81 setter = attribute.setterForMainWorld; |
82 } | 82 } |
83 (attribute.onPrototype ? prototype : instance)->SetAccessor(v8::String::
NewSymbol(attribute.name), | 83 (attribute.onPrototype ? prototype : instance)->SetAccessor(v8::String::
NewSymbol(attribute.name), |
84 getter, | 84 getter, |
85 setter, | 85 setter, |
86 v8::External::New(attribute.data), | 86 v8::External::New(const_cast<WrapperTypeInfo*>(attribute.data)), |
87 attribute.settings, | 87 attribute.settings, |
88 attribute.attribute); | 88 attribute.attribute); |
89 } | 89 } |
90 | 90 |
91 // ConstantConfiguration translates into calls to Set() for setting up an | 91 // ConstantConfiguration translates into calls to Set() for setting up an |
92 // object's constants. It sets the constant on both the FunctionTemplate and | 92 // object's constants. It sets the constant on both the FunctionTemplate and |
93 // the ObjectTemplate. PropertyAttributes is always ReadOnly. | 93 // the ObjectTemplate. PropertyAttributes is always ReadOnly. |
94 struct ConstantConfiguration { | 94 struct ConstantConfiguration { |
95 const char* const name; | 95 const char* const name; |
96 int value; | 96 int value; |
(...skipping 11 matching lines...) Expand all Loading... |
108 }; | 108 }; |
109 | 109 |
110 static void installCallbacks(v8::Handle<v8::ObjectTemplate>, v8::Handle<v8::
Signature>, v8::PropertyAttribute, const MethodConfiguration*, size_t callbackCo
unt, v8::Isolate*, WrapperWorldType); | 110 static void installCallbacks(v8::Handle<v8::ObjectTemplate>, v8::Handle<v8::
Signature>, v8::PropertyAttribute, const MethodConfiguration*, size_t callbackCo
unt, v8::Isolate*, WrapperWorldType); |
111 | 111 |
112 static v8::Local<v8::Signature> installDOMClassTemplate(v8::Handle<v8::Funct
ionTemplate>, const char* interfaceName, v8::Handle<v8::FunctionTemplate> parent
Class, size_t fieldCount, const AttributeConfiguration*, size_t attributeCount,
const MethodConfiguration*, size_t callbackCount, v8::Isolate*, WrapperWorldType
); | 112 static v8::Local<v8::Signature> installDOMClassTemplate(v8::Handle<v8::Funct
ionTemplate>, const char* interfaceName, v8::Handle<v8::FunctionTemplate> parent
Class, size_t fieldCount, const AttributeConfiguration*, size_t attributeCount,
const MethodConfiguration*, size_t callbackCount, v8::Isolate*, WrapperWorldType
); |
113 }; | 113 }; |
114 | 114 |
115 } // namespace WebCore | 115 } // namespace WebCore |
116 | 116 |
117 #endif // V8DOMConfiguration_h | 117 #endif // V8DOMConfiguration_h |
OLD | NEW |