Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(125)

Side by Side Diff: sky/engine/bindings/core/v8/V8DOMConfiguration.cpp

Issue 922053002: Remove unused V8 integration code in Sky (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 * Copyright (C) 2012 Google Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
14 * its contributors may be used to endorse or promote products derived
15 * from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29 #include "sky/engine/config.h"
30 #include "sky/engine/bindings/core/v8/V8DOMConfiguration.h"
31
32 #include "sky/engine/bindings/core/v8/V8ObjectConstructor.h"
33 #include "sky/engine/platform/TraceEvent.h"
34
35 namespace blink {
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)
38 {
39 for (size_t i = 0; i < attributeCount; ++i)
40 installAttribute(instanceTemplate, prototype, attributes[i], isolate);
41 }
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)
44 {
45 DOMWrapperWorld& world = DOMWrapperWorld::current(isolate);
46 for (size_t i = 0; i < accessorCount; ++i) {
47 v8::FunctionCallback getterCallback = accessors[i].getter;
48 v8::FunctionCallback setterCallback = accessors[i].setter;
49 if (world.isMainWorld()) {
50 if (accessors[i].getterForMainWorld)
51 getterCallback = accessors[i].getterForMainWorld;
52 if (accessors[i].setterForMainWorld)
53 setterCallback = accessors[i].setterForMainWorld;
54 }
55
56 v8::Local<v8::FunctionTemplate> getter;
57 if (getterCallback) {
58 getter = v8::FunctionTemplate::New(isolate, getterCallback, v8::Exte rnal::New(isolate, const_cast<WrapperTypeInfo*>(accessors[i].data)), signature, 0);
59 getter->RemovePrototype();
60 }
61 v8::Local<v8::FunctionTemplate> setter;
62 if (setterCallback) {
63 setter = v8::FunctionTemplate::New(isolate, setterCallback, v8::Exte rnal::New(isolate, const_cast<WrapperTypeInfo*>(accessors[i].data)), signature, 1);
64 setter->RemovePrototype();
65 }
66 prototype->SetAccessorProperty(v8AtomicString(isolate, accessors[i].name ), getter, setter, accessors[i].attribute, accessors[i].settings);
67 }
68 }
69
70 void V8DOMConfiguration::installConstants(v8::Handle<v8::FunctionTemplate> funct ionDescriptor, v8::Handle<v8::ObjectTemplate> prototype, const ConstantConfigura tion* constants, size_t constantCount, v8::Isolate* isolate)
71 {
72 for (size_t i = 0; i < constantCount; ++i) {
73 const ConstantConfiguration* constant = &constants[i];
74 v8::Handle<v8::String> constantName = v8AtomicString(isolate, constant-> name);
75 switch (constant->type) {
76 case ConstantTypeShort:
77 case ConstantTypeLong:
78 case ConstantTypeUnsignedShort:
79 functionDescriptor->Set(constantName, v8::Integer::New(isolate, cons tant->ivalue), static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontDelete) );
80 prototype->Set(constantName, v8::Integer::New(isolate, constant->iva lue), static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontDelete));
81 break;
82 case ConstantTypeUnsignedLong:
83 functionDescriptor->Set(constantName, v8::Integer::NewFromUnsigned(i solate, constant->ivalue), static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8: :DontDelete));
84 prototype->Set(constantName, v8::Integer::NewFromUnsigned(isolate, c onstant->ivalue), static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontDele te));
85 break;
86 case ConstantTypeFloat:
87 case ConstantTypeDouble:
88 functionDescriptor->Set(constantName, v8::Number::New(isolate, const ant->dvalue), static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontDelete)) ;
89 prototype->Set(constantName, v8::Number::New(isolate, constant->dval ue), static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontDelete));
90 break;
91 case ConstantTypeString:
92 functionDescriptor->Set(constantName, v8::String::NewFromUtf8(isolat e, constant->svalue), static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::Dont Delete));
93 prototype->Set(constantName, v8::String::NewFromUtf8(isolate, consta nt->svalue), static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontDelete));
94 break;
95 default:
96 ASSERT_NOT_REACHED();
97 }
98 }
99 }
100
101 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)
102 {
103 for (size_t i = 0; i < callbackCount; ++i)
104 installMethod(prototype, signature, attributes, callbacks[i], isolate);
105 }
106
107 v8::Handle<v8::FunctionTemplate> V8DOMConfiguration::functionTemplateForCallback (v8::Handle<v8::Signature> signature, v8::FunctionCallback callback, int length, v8::Isolate* isolate)
108 {
109 v8::Local<v8::FunctionTemplate> functionTemplate = v8::FunctionTemplate::New (isolate, callback, v8Undefined(), signature, length);
110 functionTemplate->RemovePrototype();
111 return functionTemplate;
112 }
113
114 v8::Local<v8::Signature> V8DOMConfiguration::installDOMClassTemplate(v8::Handle< v8::FunctionTemplate> functionDescriptor, const char* interfaceName, v8::Handle< v8::FunctionTemplate> parentClass, size_t fieldCount,
115 const AttributeConfiguration* attributes, size_t attributeCount,
116 const AccessorConfiguration* accessors, size_t accessorCount,
117 const MethodConfiguration* callbacks, size_t callbackCount,
118 v8::Isolate* isolate)
119 {
120 functionDescriptor->SetClassName(v8AtomicString(isolate, interfaceName));
121 v8::Local<v8::ObjectTemplate> instanceTemplate = functionDescriptor->Instanc eTemplate();
122 instanceTemplate->SetInternalFieldCount(fieldCount);
123 if (!parentClass.IsEmpty()) {
124 functionDescriptor->Inherit(parentClass);
125 // Marks the prototype object as one of native-backed objects.
126 // This is needed since bug 110436 asks WebKit to tell native-initiated prototypes from pure-JS ones.
127 // This doesn't mark kinds "root" classes like Node, where setting this changes prototype chain structure.
128 v8::Local<v8::ObjectTemplate> prototype = functionDescriptor->PrototypeT emplate();
129 prototype->SetInternalFieldCount(v8PrototypeInternalFieldcount);
130 }
131
132 v8::Local<v8::Signature> defaultSignature = v8::Signature::New(isolate, func tionDescriptor);
133 if (attributeCount)
134 installAttributes(instanceTemplate, functionDescriptor->PrototypeTemplat e(), attributes, attributeCount, isolate);
135 if (accessorCount)
136 installAccessors(functionDescriptor->PrototypeTemplate(), defaultSignatu re, accessors, accessorCount, isolate);
137 if (callbackCount)
138 installMethods(functionDescriptor->PrototypeTemplate(), defaultSignature , static_cast<v8::PropertyAttribute>(v8::DontDelete), callbacks, callbackCount, isolate);
139 return defaultSignature;
140 }
141
142 v8::Handle<v8::FunctionTemplate> V8DOMConfiguration::domClassTemplate(v8::Isolat e* isolate, WrapperTypeInfo* wrapperTypeInfo, void (*configureDOMClassTemplate)( v8::Handle<v8::FunctionTemplate>, v8::Isolate*))
143 {
144 V8PerIsolateData* data = V8PerIsolateData::from(isolate);
145 v8::Local<v8::FunctionTemplate> result = data->existingDOMTemplate(wrapperTy peInfo);
146 if (!result.IsEmpty())
147 return result;
148
149 TRACE_EVENT_SCOPED_SAMPLING_STATE("blink", "BuildDOMTemplate");
150 result = v8::FunctionTemplate::New(isolate, V8ObjectConstructor::isValidCons tructorMode);
151 configureDOMClassTemplate(result, isolate);
152 data->setDOMTemplate(wrapperTypeInfo, result);
153 return result;
154 }
155
156 } // namespace blink
OLDNEW
« no previous file with comments | « sky/engine/bindings/core/v8/V8DOMConfiguration.h ('k') | sky/engine/bindings/core/v8/V8DOMWrapper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698