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 16 matching lines...) Expand all Loading... |
27 */ | 27 */ |
28 | 28 |
29 #include "config.h" | 29 #include "config.h" |
30 #include "bindings/core/v8/V8DOMConfiguration.h" | 30 #include "bindings/core/v8/V8DOMConfiguration.h" |
31 | 31 |
32 #include "bindings/core/v8/V8ObjectConstructor.h" | 32 #include "bindings/core/v8/V8ObjectConstructor.h" |
33 #include "platform/TraceEvent.h" | 33 #include "platform/TraceEvent.h" |
34 | 34 |
35 namespace blink { | 35 namespace blink { |
36 | 36 |
37 void V8DOMConfiguration::installAttributes(v8::Handle<v8::ObjectTemplate> instan
ceTemplate, v8::Handle<v8::ObjectTemplate> prototype, const AttributeConfigurati
on* attributes, size_t attributeCount, v8::Isolate* isolate) | 37 void V8DOMConfiguration::installAttributes(v8::Isolate* isolate, v8::Handle<v8::
ObjectTemplate> instanceTemplate, v8::Handle<v8::ObjectTemplate> prototype, cons
t AttributeConfiguration* attributes, size_t attributeCount) |
38 { | 38 { |
39 for (size_t i = 0; i < attributeCount; ++i) | 39 for (size_t i = 0; i < attributeCount; ++i) |
40 installAttribute(instanceTemplate, prototype, attributes[i], isolate); | 40 installAttribute(instanceTemplate, prototype, attributes[i], isolate); |
41 } | 41 } |
42 | 42 |
43 void V8DOMConfiguration::installAccessors(v8::Handle<v8::ObjectTemplate> prototy
pe, v8::Handle<v8::Signature> signature, const AccessorConfiguration* accessors,
size_t accessorCount, v8::Isolate* isolate) | 43 void V8DOMConfiguration::installAccessors(v8::Isolate* isolate, v8::Handle<v8::O
bjectTemplate> prototype, v8::Handle<v8::Signature> signature, const AccessorCon
figuration* accessors, size_t accessorCount) |
44 { | 44 { |
45 DOMWrapperWorld& world = DOMWrapperWorld::current(isolate); | 45 DOMWrapperWorld& world = DOMWrapperWorld::current(isolate); |
46 for (size_t i = 0; i < accessorCount; ++i) { | 46 for (size_t i = 0; i < accessorCount; ++i) { |
47 if (accessors[i].exposeConfiguration == OnlyExposedToPrivateScript && !w
orld.isPrivateScriptIsolatedWorld()) | 47 if (accessors[i].exposeConfiguration == OnlyExposedToPrivateScript && !w
orld.isPrivateScriptIsolatedWorld()) |
48 continue; | 48 continue; |
49 | 49 |
50 v8::FunctionCallback getterCallback = accessors[i].getter; | 50 v8::FunctionCallback getterCallback = accessors[i].getter; |
51 v8::FunctionCallback setterCallback = accessors[i].setter; | 51 v8::FunctionCallback setterCallback = accessors[i].setter; |
52 if (world.isMainWorld()) { | 52 if (world.isMainWorld()) { |
53 if (accessors[i].getterForMainWorld) | 53 if (accessors[i].getterForMainWorld) |
(...skipping 18 matching lines...) Expand all Loading... |
72 | 72 |
73 // Constant installation | 73 // Constant installation |
74 // | 74 // |
75 // installConstants() is be used for simple constants. It installs constants | 75 // installConstants() is be used for simple constants. It installs constants |
76 // using v8::Template::Set(), which results in a property that is much faster to | 76 // using v8::Template::Set(), which results in a property that is much faster to |
77 // access from scripts. | 77 // access from scripts. |
78 // installConstant() is used when some C++ code needs to be executed when the | 78 // installConstant() is used when some C++ code needs to be executed when the |
79 // constant is accessed, e.g. to handle deprecation or measuring usage. The | 79 // constant is accessed, e.g. to handle deprecation or measuring usage. The |
80 // property appears the same to scripts, but is slower to access. | 80 // property appears the same to scripts, but is slower to access. |
81 | 81 |
82 void V8DOMConfiguration::installConstants(v8::Handle<v8::FunctionTemplate> funct
ionDescriptor, v8::Handle<v8::ObjectTemplate> prototype, const ConstantConfigura
tion* constants, size_t constantCount, v8::Isolate* isolate) | 82 void V8DOMConfiguration::installConstants(v8::Isolate* isolate, v8::Handle<v8::F
unctionTemplate> functionDescriptor, v8::Handle<v8::ObjectTemplate> prototype, c
onst ConstantConfiguration* constants, size_t constantCount) |
83 { | 83 { |
84 for (size_t i = 0; i < constantCount; ++i) { | 84 for (size_t i = 0; i < constantCount; ++i) { |
85 const ConstantConfiguration* constant = &constants[i]; | 85 const ConstantConfiguration* constant = &constants[i]; |
86 v8::Handle<v8::String> constantName = v8AtomicString(isolate, constant->
name); | 86 v8::Handle<v8::String> constantName = v8AtomicString(isolate, constant->
name); |
87 switch (constant->type) { | 87 switch (constant->type) { |
88 case ConstantTypeShort: | 88 case ConstantTypeShort: |
89 case ConstantTypeLong: | 89 case ConstantTypeLong: |
90 case ConstantTypeUnsignedShort: | 90 case ConstantTypeUnsignedShort: |
91 functionDescriptor->Set(constantName, v8::Integer::New(isolate, cons
tant->ivalue), static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontDelete)
); | 91 functionDescriptor->Set(constantName, v8::Integer::New(isolate, cons
tant->ivalue), static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontDelete)
); |
92 prototype->Set(constantName, v8::Integer::New(isolate, constant->iva
lue), static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontDelete)); | 92 prototype->Set(constantName, v8::Integer::New(isolate, constant->iva
lue), static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontDelete)); |
(...skipping 10 matching lines...) Expand all Loading... |
103 case ConstantTypeString: | 103 case ConstantTypeString: |
104 functionDescriptor->Set(constantName, v8::String::NewFromUtf8(isolat
e, constant->svalue), static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::Dont
Delete)); | 104 functionDescriptor->Set(constantName, v8::String::NewFromUtf8(isolat
e, constant->svalue), static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::Dont
Delete)); |
105 prototype->Set(constantName, v8::String::NewFromUtf8(isolate, consta
nt->svalue), static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontDelete)); | 105 prototype->Set(constantName, v8::String::NewFromUtf8(isolate, consta
nt->svalue), static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontDelete)); |
106 break; | 106 break; |
107 default: | 107 default: |
108 ASSERT_NOT_REACHED(); | 108 ASSERT_NOT_REACHED(); |
109 } | 109 } |
110 } | 110 } |
111 } | 111 } |
112 | 112 |
113 void V8DOMConfiguration::installConstant(v8::Handle<v8::FunctionTemplate> functi
onDescriptor, v8::Handle<v8::ObjectTemplate> prototype, const char* name, v8::Ac
cessorGetterCallback getter, v8::Isolate* isolate) | 113 void V8DOMConfiguration::installConstant(v8::Isolate* isolate, v8::Handle<v8::Fu
nctionTemplate> functionDescriptor, v8::Handle<v8::ObjectTemplate> prototype, co
nst char* name, v8::AccessorGetterCallback getter) |
114 { | 114 { |
115 v8::Handle<v8::String> constantName = v8AtomicString(isolate, name); | 115 v8::Handle<v8::String> constantName = v8AtomicString(isolate, name); |
116 functionDescriptor->SetNativeDataProperty(constantName, getter, 0, v8::Handl
e<v8::Value>(), static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontDelete
)); | 116 functionDescriptor->SetNativeDataProperty(constantName, getter, 0, v8::Handl
e<v8::Value>(), static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontDelete
)); |
117 prototype->SetNativeDataProperty(constantName, getter, 0, v8::Handle<v8::Val
ue>(), static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontDelete)); | 117 prototype->SetNativeDataProperty(constantName, getter, 0, v8::Handle<v8::Val
ue>(), static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontDelete)); |
118 } | 118 } |
119 | 119 |
120 void V8DOMConfiguration::installMethods(v8::Handle<v8::ObjectTemplate> prototype
, v8::Handle<v8::Signature> signature, v8::PropertyAttribute attributes, const M
ethodConfiguration* callbacks, size_t callbackCount, v8::Isolate* isolate) | 120 void V8DOMConfiguration::installMethods(v8::Isolate* isolate, v8::Handle<v8::Obj
ectTemplate> prototype, v8::Handle<v8::Signature> signature, v8::PropertyAttribu
te attributes, const MethodConfiguration* callbacks, size_t callbackCount) |
121 { | 121 { |
122 for (size_t i = 0; i < callbackCount; ++i) | 122 for (size_t i = 0; i < callbackCount; ++i) |
123 installMethod(prototype, signature, attributes, callbacks[i], isolate); | 123 installMethod(prototype, signature, attributes, callbacks[i], isolate); |
124 } | 124 } |
125 | 125 |
126 v8::Handle<v8::FunctionTemplate> V8DOMConfiguration::functionTemplateForCallback
(v8::Isolate* isolate, v8::Handle<v8::Signature> signature, v8::FunctionCallback
callback, int length) | 126 v8::Handle<v8::FunctionTemplate> V8DOMConfiguration::functionTemplateForCallback
(v8::Isolate* isolate, v8::Handle<v8::Signature> signature, v8::FunctionCallback
callback, int length) |
127 { | 127 { |
128 v8::Local<v8::FunctionTemplate> functionTemplate = v8::FunctionTemplate::New
(isolate, callback, v8Undefined(), signature, length); | 128 v8::Local<v8::FunctionTemplate> functionTemplate = v8::FunctionTemplate::New
(isolate, callback, v8Undefined(), signature, length); |
129 functionTemplate->RemovePrototype(); | 129 functionTemplate->RemovePrototype(); |
130 return functionTemplate; | 130 return functionTemplate; |
(...skipping 12 matching lines...) Expand all Loading... |
143 functionDescriptor->Inherit(parentClass); | 143 functionDescriptor->Inherit(parentClass); |
144 // Marks the prototype object as one of native-backed objects. | 144 // Marks the prototype object as one of native-backed objects. |
145 // This is needed since bug 110436 asks WebKit to tell native-initiated
prototypes from pure-JS ones. | 145 // This is needed since bug 110436 asks WebKit to tell native-initiated
prototypes from pure-JS ones. |
146 // This doesn't mark kinds "root" classes like Node, where setting this
changes prototype chain structure. | 146 // This doesn't mark kinds "root" classes like Node, where setting this
changes prototype chain structure. |
147 v8::Local<v8::ObjectTemplate> prototype = functionDescriptor->PrototypeT
emplate(); | 147 v8::Local<v8::ObjectTemplate> prototype = functionDescriptor->PrototypeT
emplate(); |
148 prototype->SetInternalFieldCount(v8PrototypeInternalFieldcount); | 148 prototype->SetInternalFieldCount(v8PrototypeInternalFieldcount); |
149 } | 149 } |
150 | 150 |
151 v8::Local<v8::Signature> defaultSignature = v8::Signature::New(isolate, func
tionDescriptor); | 151 v8::Local<v8::Signature> defaultSignature = v8::Signature::New(isolate, func
tionDescriptor); |
152 if (attributeCount) | 152 if (attributeCount) |
153 installAttributes(instanceTemplate, functionDescriptor->PrototypeTemplat
e(), attributes, attributeCount, isolate); | 153 installAttributes(isolate, instanceTemplate, functionDescriptor->Prototy
peTemplate(), attributes, attributeCount); |
154 if (accessorCount) | 154 if (accessorCount) |
155 installAccessors(functionDescriptor->PrototypeTemplate(), defaultSignatu
re, accessors, accessorCount, isolate); | 155 installAccessors(isolate, functionDescriptor->PrototypeTemplate(), defau
ltSignature, accessors, accessorCount); |
156 if (callbackCount) | 156 if (callbackCount) |
157 installMethods(functionDescriptor->PrototypeTemplate(), defaultSignature
, static_cast<v8::PropertyAttribute>(v8::DontDelete), callbacks, callbackCount,
isolate); | 157 installMethods(isolate, functionDescriptor->PrototypeTemplate(), default
Signature, static_cast<v8::PropertyAttribute>(v8::DontDelete), callbacks, callba
ckCount); |
158 return defaultSignature; | 158 return defaultSignature; |
159 } | 159 } |
160 | 160 |
161 v8::Handle<v8::FunctionTemplate> V8DOMConfiguration::domClassTemplate(v8::Isolat
e* isolate, WrapperTypeInfo* wrapperTypeInfo, void (*configureDOMClassTemplate)(
v8::Handle<v8::FunctionTemplate>, v8::Isolate*)) | 161 v8::Handle<v8::FunctionTemplate> V8DOMConfiguration::domClassTemplate(v8::Isolat
e* isolate, WrapperTypeInfo* wrapperTypeInfo, void (*configureDOMClassTemplate)(
v8::Handle<v8::FunctionTemplate>, v8::Isolate*)) |
162 { | 162 { |
163 V8PerIsolateData* data = V8PerIsolateData::from(isolate); | 163 V8PerIsolateData* data = V8PerIsolateData::from(isolate); |
164 v8::Local<v8::FunctionTemplate> result = data->existingDOMTemplate(wrapperTy
peInfo); | 164 v8::Local<v8::FunctionTemplate> result = data->existingDOMTemplate(wrapperTy
peInfo); |
165 if (!result.IsEmpty()) | 165 if (!result.IsEmpty()) |
166 return result; | 166 return result; |
167 | 167 |
168 TRACE_EVENT_SCOPED_SAMPLING_STATE("blink", "BuildDOMTemplate"); | 168 TRACE_EVENT_SCOPED_SAMPLING_STATE("blink", "BuildDOMTemplate"); |
169 result = v8::FunctionTemplate::New(isolate, V8ObjectConstructor::isValidCons
tructorMode); | 169 result = v8::FunctionTemplate::New(isolate, V8ObjectConstructor::isValidCons
tructorMode); |
170 configureDOMClassTemplate(result, isolate); | 170 configureDOMClassTemplate(result, isolate); |
171 data->setDOMTemplate(wrapperTypeInfo, result); | 171 data->setDOMTemplate(wrapperTypeInfo, result); |
172 return result; | 172 return result; |
173 } | 173 } |
174 | 174 |
175 } // namespace blink | 175 } // namespace blink |
OLD | NEW |