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 21 matching lines...) Expand all Loading... |
32 #include "bindings/v8/V8Binding.h" | 32 #include "bindings/v8/V8Binding.h" |
33 | 33 |
34 namespace WebCore { | 34 namespace WebCore { |
35 | 35 |
36 void V8DOMConfiguration::installAttributes(v8::Handle<v8::ObjectTemplate> instan
ce, v8::Handle<v8::ObjectTemplate> prototype, const AttributeConfiguration* attr
ibutes, size_t attributeCount, v8::Isolate* isolate, WrapperWorldType currentWor
ldType) | 36 void V8DOMConfiguration::installAttributes(v8::Handle<v8::ObjectTemplate> instan
ce, v8::Handle<v8::ObjectTemplate> prototype, const AttributeConfiguration* attr
ibutes, size_t attributeCount, v8::Isolate* isolate, WrapperWorldType currentWor
ldType) |
37 { | 37 { |
38 for (size_t i = 0; i < attributeCount; ++i) | 38 for (size_t i = 0; i < attributeCount; ++i) |
39 installAttribute(instance, prototype, attributes[i], isolate, currentWor
ldType); | 39 installAttribute(instance, prototype, attributes[i], isolate, currentWor
ldType); |
40 } | 40 } |
41 | 41 |
| 42 void V8DOMConfiguration::installAccessors(v8::Handle<v8::ObjectTemplate> prototy
pe, v8::Handle<v8::Signature> signature, const AccessorConfiguration* accessors,
size_t accessorCount, v8::Isolate* isolate, WrapperWorldType currentWorldType) |
| 43 { |
| 44 for (size_t i = 0; i < accessorCount; ++i) { |
| 45 v8::FunctionCallback getterCallback = accessors[i].getter; |
| 46 v8::FunctionCallback setterCallback = accessors[i].setter; |
| 47 if (currentWorldType == MainWorld) { |
| 48 if (accessors[i].getterForMainWorld) |
| 49 getterCallback = accessors[i].getterForMainWorld; |
| 50 if (accessors[i].setterForMainWorld) |
| 51 setterCallback = accessors[i].setterForMainWorld; |
| 52 } |
| 53 |
| 54 v8::Local<v8::FunctionTemplate> getter; |
| 55 if (getterCallback) { |
| 56 getter = v8::FunctionTemplate::New(getterCallback, v8::External::New
(accessors[i].data), signature, 0); |
| 57 getter->RemovePrototype(); |
| 58 } |
| 59 v8::Local<v8::FunctionTemplate> setter; |
| 60 if (setterCallback) { |
| 61 setter = v8::FunctionTemplate::New(setterCallback, v8::External::New
(accessors[i].data), signature, 1); |
| 62 setter->RemovePrototype(); |
| 63 } |
| 64 |
| 65 prototype->SetAccessorProperty(v8::String::NewSymbol(accessors[i].name),
getter, setter, accessors[i].attribute, accessors[i].settings); |
| 66 } |
| 67 } |
| 68 |
42 void V8DOMConfiguration::installConstants(v8::Handle<v8::FunctionTemplate> funct
ionDescriptor, v8::Handle<v8::ObjectTemplate> prototype, const ConstantConfigura
tion* constants, size_t constantCount, v8::Isolate* isolate) | 69 void V8DOMConfiguration::installConstants(v8::Handle<v8::FunctionTemplate> funct
ionDescriptor, v8::Handle<v8::ObjectTemplate> prototype, const ConstantConfigura
tion* constants, size_t constantCount, v8::Isolate* isolate) |
43 { | 70 { |
44 for (size_t i = 0; i < constantCount; ++i) { | 71 for (size_t i = 0; i < constantCount; ++i) { |
45 const ConstantConfiguration* constant = &constants[i]; | 72 const ConstantConfiguration* constant = &constants[i]; |
46 functionDescriptor->Set(v8::String::NewSymbol(constant->name), v8::Integ
er::New(constant->value, isolate), static_cast<v8::PropertyAttribute>(v8::ReadOn
ly | v8::DontDelete)); | 73 functionDescriptor->Set(v8::String::NewSymbol(constant->name), v8::Integ
er::New(constant->value, isolate), static_cast<v8::PropertyAttribute>(v8::ReadOn
ly | v8::DontDelete)); |
47 prototype->Set(v8::String::NewSymbol(constant->name), v8::Integer::New(c
onstant->value, isolate), static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::
DontDelete)); | 74 prototype->Set(v8::String::NewSymbol(constant->name), v8::Integer::New(c
onstant->value, isolate), static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::
DontDelete)); |
48 } | 75 } |
49 } | 76 } |
50 | 77 |
51 void V8DOMConfiguration::installCallbacks(v8::Handle<v8::ObjectTemplate> prototy
pe, v8::Handle<v8::Signature> signature, v8::PropertyAttribute attributes, const
MethodConfiguration* callbacks, size_t callbackCount, v8::Isolate*, WrapperWorl
dType currentWorldType) | 78 void V8DOMConfiguration::installCallbacks(v8::Handle<v8::ObjectTemplate> prototy
pe, v8::Handle<v8::Signature> signature, v8::PropertyAttribute attributes, const
MethodConfiguration* callbacks, size_t callbackCount, v8::Isolate*, WrapperWorl
dType currentWorldType) |
52 { | 79 { |
53 for (size_t i = 0; i < callbackCount; ++i) { | 80 for (size_t i = 0; i < callbackCount; ++i) { |
54 v8::FunctionCallback callback = callbacks[i].callback; | 81 v8::FunctionCallback callback = callbacks[i].callback; |
55 if (currentWorldType == MainWorld && callbacks[i].callbackForMainWorld) | 82 if (currentWorldType == MainWorld && callbacks[i].callbackForMainWorld) |
56 callback = callbacks[i].callbackForMainWorld; | 83 callback = callbacks[i].callbackForMainWorld; |
57 v8::Local<v8::FunctionTemplate> functionTemplate = v8::FunctionTemplate:
:New(callback, v8Undefined(), signature, callbacks[i].length); | 84 v8::Local<v8::FunctionTemplate> functionTemplate = v8::FunctionTemplate:
:New(callback, v8Undefined(), signature, callbacks[i].length); |
58 functionTemplate->RemovePrototype(); | 85 functionTemplate->RemovePrototype(); |
59 prototype->Set(v8::String::NewSymbol(callbacks[i].name), functionTemplat
e, attributes); | 86 prototype->Set(v8::String::NewSymbol(callbacks[i].name), functionTemplat
e, attributes); |
60 } | 87 } |
61 } | 88 } |
62 | 89 |
63 v8::Local<v8::Signature> V8DOMConfiguration::installDOMClassTemplate(v8::Handle<
v8::FunctionTemplate> functionDescriptor, const char* interfaceName, v8::Handle<
v8::FunctionTemplate> parentClass, | 90 v8::Local<v8::Signature> V8DOMConfiguration::installDOMClassTemplate(v8::Handle<
v8::FunctionTemplate> functionDescriptor, const char* interfaceName, v8::Handle<
v8::FunctionTemplate> parentClass, size_t fieldCount, |
64 size_t fieldCount, const AttributeConfiguration* attributes, size_t attribut
eCount, const MethodConfiguration* callbacks, size_t callbackCount, v8::Isolate*
isolate, WrapperWorldType currentWorldType) | 91 const AttributeConfiguration* attributes, size_t attributeCount, |
| 92 const AccessorConfiguration* accessors, size_t accessorCount, |
| 93 const MethodConfiguration* callbacks, size_t callbackCount, |
| 94 v8::Isolate* isolate, WrapperWorldType currentWorldType) |
65 { | 95 { |
66 functionDescriptor->SetClassName(v8::String::NewSymbol(interfaceName)); | 96 functionDescriptor->SetClassName(v8::String::NewSymbol(interfaceName)); |
67 v8::Local<v8::ObjectTemplate> instance = functionDescriptor->InstanceTemplat
e(); | 97 v8::Local<v8::ObjectTemplate> instance = functionDescriptor->InstanceTemplat
e(); |
68 instance->SetInternalFieldCount(fieldCount); | 98 instance->SetInternalFieldCount(fieldCount); |
69 if (!parentClass.IsEmpty()) { | 99 if (!parentClass.IsEmpty()) { |
70 functionDescriptor->Inherit(parentClass); | 100 functionDescriptor->Inherit(parentClass); |
71 // Marks the prototype object as one of native-backed objects. | 101 // Marks the prototype object as one of native-backed objects. |
72 // This is needed since bug 110436 asks WebKit to tell native-initiated
prototypes from pure-JS ones. | 102 // This is needed since bug 110436 asks WebKit to tell native-initiated
prototypes from pure-JS ones. |
73 // This doesn't mark kinds "root" classes like Node, where setting this
changes prototype chain structure. | 103 // This doesn't mark kinds "root" classes like Node, where setting this
changes prototype chain structure. |
74 v8::Local<v8::ObjectTemplate> prototype = functionDescriptor->PrototypeT
emplate(); | 104 v8::Local<v8::ObjectTemplate> prototype = functionDescriptor->PrototypeT
emplate(); |
75 prototype->SetInternalFieldCount(v8PrototypeInternalFieldcount); | 105 prototype->SetInternalFieldCount(v8PrototypeInternalFieldcount); |
76 } | 106 } |
77 | 107 |
| 108 v8::Local<v8::Signature> defaultSignature = v8::Signature::New(functionDescr
iptor); |
78 if (attributeCount) | 109 if (attributeCount) |
79 installAttributes(instance, functionDescriptor->PrototypeTemplate(), att
ributes, attributeCount, isolate, currentWorldType); | 110 installAttributes(instance, functionDescriptor->PrototypeTemplate(), att
ributes, attributeCount, isolate, currentWorldType); |
80 v8::Local<v8::Signature> defaultSignature = v8::Signature::New(functionDescr
iptor); | 111 if (accessorCount) |
| 112 installAccessors(functionDescriptor->PrototypeTemplate(), defaultSignatu
re, accessors, accessorCount, isolate, currentWorldType); |
81 if (callbackCount) | 113 if (callbackCount) |
82 installCallbacks(functionDescriptor->PrototypeTemplate(), defaultSignatu
re, static_cast<v8::PropertyAttribute>(v8::DontDelete), callbacks, callbackCount
, isolate, currentWorldType); | 114 installCallbacks(functionDescriptor->PrototypeTemplate(), defaultSignatu
re, static_cast<v8::PropertyAttribute>(v8::DontDelete), callbacks, callbackCount
, isolate, currentWorldType); |
83 return defaultSignature; | 115 return defaultSignature; |
84 } | 116 } |
85 | 117 |
86 } // namespace WebCore | 118 } // namespace WebCore |
OLD | NEW |