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

Side by Side Diff: src/api-natives.cc

Issue 1409593002: [api] expose API for adding per-context Intrinsics to Templates (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 2 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
1 // Copyright 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/api-natives.h" 5 #include "src/api-natives.h"
6 6
7 #include "src/api.h" 7 #include "src/api.h"
8 #include "src/isolate-inl.h" 8 #include "src/isolate-inl.h"
9 #include "src/lookup.h" 9 #include "src/lookup.h"
10 #include "src/messages.h" 10 #include "src/messages.h"
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 } 141 }
142 } 142 }
143 143
144 private: 144 private:
145 Isolate* isolate_; 145 Isolate* isolate_;
146 const bool disabled_; 146 const bool disabled_;
147 Handle<JSObject> obj_; 147 Handle<JSObject> obj_;
148 }; 148 };
149 149
150 150
151 Object* GetIntrinsic(Context* context, v8::Intrinsic intrinsic) {
152 switch (intrinsic) {
153 #define GET_INTRINSIC_VALUE(name, iname) \
154 case v8::k##name: \
155 return context->iname();
156 V8_INTRINSICS_LIST(GET_INTRINSIC_VALUE)
157 #undef GET_INTRINSIC_VALUE
158 }
159 return nullptr;
160 }
161
162
163 Context* GetCurrentContext(Isolate* isolate) {
Toon Verwaest 2015/10/20 15:00:54 This seems unnecessary given that context->iname()
caitp (gmail) 2015/10/20 15:38:06 Ok
164 Context* context = isolate->context();
165 if (context != nullptr) return context->native_context();
166 return nullptr;
167 }
168
169
151 MaybeHandle<JSObject> ConfigureInstance(Isolate* isolate, Handle<JSObject> obj, 170 MaybeHandle<JSObject> ConfigureInstance(Isolate* isolate, Handle<JSObject> obj,
152 Handle<TemplateInfo> data) { 171 Handle<TemplateInfo> data) {
153 auto property_list = handle(data->property_list(), isolate); 172 auto property_list = handle(data->property_list(), isolate);
154 if (property_list->IsUndefined()) return obj; 173 if (property_list->IsUndefined()) return obj;
155 // TODO(dcarney): just use a FixedArray here. 174 // TODO(dcarney): just use a FixedArray here.
156 NeanderArray properties(property_list); 175 NeanderArray properties(property_list);
157 if (properties.length() == 0) return obj; 176 if (properties.length() == 0) return obj;
158 HandleScope scope(isolate); 177 HandleScope scope(isolate);
159 // Disable access checks while instantiating the object. 178 // Disable access checks while instantiating the object.
160 AccessCheckDisableScope access_check_scope(isolate, obj); 179 AccessCheckDisableScope access_check_scope(isolate, obj);
161 180
162 int i = 0; 181 int i = 0;
163 for (int c = 0; c < data->number_of_properties(); c++) { 182 for (int c = 0; c < data->number_of_properties(); c++) {
164 auto name = handle(Name::cast(properties.get(i++)), isolate); 183 auto name = handle(Name::cast(properties.get(i++)), isolate);
165 PropertyDetails details(Smi::cast(properties.get(i++))); 184 auto bit = handle(properties.get(i++), isolate);
166 PropertyAttributes attributes = details.attributes(); 185 if (bit->IsSmi()) {
167 PropertyKind kind = details.kind(); 186 PropertyDetails details(Smi::cast(*bit));
187 PropertyAttributes attributes = details.attributes();
188 PropertyKind kind = details.kind();
168 189
169 if (kind == kData) { 190 if (kind == kData) {
170 auto prop_data = handle(properties.get(i++), isolate); 191 auto prop_data = handle(properties.get(i++), isolate);
192
193 RETURN_ON_EXCEPTION(isolate, DefineDataProperty(isolate, obj, name,
194 prop_data, attributes),
195 JSObject);
196 } else {
197 auto getter = handle(properties.get(i++), isolate);
198 auto setter = handle(properties.get(i++), isolate);
199 RETURN_ON_EXCEPTION(isolate,
200 DefineAccessorProperty(isolate, obj, name, getter,
201 setter, attributes),
202 JSObject);
203 }
204 } else {
205 // Intrinsic data property --- Get appropriate value from the current
206 // context.
207 PropertyDetails details(Smi::cast(properties.get(i++)));
208 PropertyAttributes attributes = details.attributes();
209 DCHECK_EQ(kData, details.kind());
210
211 v8::Intrinsic intrinsic =
212 static_cast<v8::Intrinsic>(Smi::cast(properties.get(i++))->value());
213 auto prop_data =
214 handle(GetIntrinsic(GetCurrentContext(isolate), intrinsic), isolate);
171 215
172 RETURN_ON_EXCEPTION(isolate, DefineDataProperty(isolate, obj, name, 216 RETURN_ON_EXCEPTION(isolate, DefineDataProperty(isolate, obj, name,
173 prop_data, attributes), 217 prop_data, attributes),
174 JSObject); 218 JSObject);
175 } else {
176 auto getter = handle(properties.get(i++), isolate);
177 auto setter = handle(properties.get(i++), isolate);
178 RETURN_ON_EXCEPTION(isolate,
179 DefineAccessorProperty(isolate, obj, name, getter,
180 setter, attributes),
181 JSObject);
182 } 219 }
183 } 220 }
184 return obj; 221 return obj;
185 } 222 }
186 223
187 224
188 MaybeHandle<JSObject> InstantiateObject(Isolate* isolate, 225 MaybeHandle<JSObject> InstantiateObject(Isolate* isolate,
189 Handle<ObjectTemplateInfo> data) { 226 Handle<ObjectTemplateInfo> data) {
190 // Enter a new scope. Recursion could otherwise create a lot of handles. 227 // Enter a new scope. Recursion could otherwise create a lot of handles.
191 HandleScope scope(isolate); 228 HandleScope scope(isolate);
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 Handle<Name> name, Handle<Object> value, 407 Handle<Name> name, Handle<Object> value,
371 PropertyAttributes attributes) { 408 PropertyAttributes attributes) {
372 const int kSize = 3; 409 const int kSize = 3;
373 PropertyDetails details(attributes, DATA, 0, PropertyCellType::kNoCell); 410 PropertyDetails details(attributes, DATA, 0, PropertyCellType::kNoCell);
374 auto details_handle = handle(details.AsSmi(), isolate); 411 auto details_handle = handle(details.AsSmi(), isolate);
375 Handle<Object> data[kSize] = {name, details_handle, value}; 412 Handle<Object> data[kSize] = {name, details_handle, value};
376 AddPropertyToPropertyList(isolate, info, kSize, data); 413 AddPropertyToPropertyList(isolate, info, kSize, data);
377 } 414 }
378 415
379 416
417 void ApiNatives::AddDataProperty(Isolate* isolate, Handle<TemplateInfo> info,
418 Handle<Name> name, v8::Intrinsic intrinsic,
419 PropertyAttributes attributes) {
420 const int kSize = 4;
421 auto value = handle(Smi::FromInt(intrinsic), isolate);
422 auto intrinsic_marker = isolate->factory()->true_value();
423 PropertyDetails details(attributes, DATA, 0, PropertyCellType::kNoCell);
424 auto details_handle = handle(details.AsSmi(), isolate);
425 Handle<Object> data[kSize] = {name, intrinsic_marker, details_handle, value};
426 AddPropertyToPropertyList(isolate, info, kSize, data);
427 }
428
429
380 void ApiNatives::AddAccessorProperty(Isolate* isolate, 430 void ApiNatives::AddAccessorProperty(Isolate* isolate,
381 Handle<TemplateInfo> info, 431 Handle<TemplateInfo> info,
382 Handle<Name> name, Handle<Object> getter, 432 Handle<Name> name, Handle<Object> getter,
383 Handle<Object> setter, 433 Handle<Object> setter,
384 PropertyAttributes attributes) { 434 PropertyAttributes attributes) {
385 #ifdef V8_JS_ACCESSORS 435 #ifdef V8_JS_ACCESSORS
386 DCHECK(getter.is_null() || getter->IsFunctionTemplateInfo() || 436 DCHECK(getter.is_null() || getter->IsFunctionTemplateInfo() ||
387 getter->IsJSFunction()); 437 getter->IsJSFunction());
388 DCHECK(setter.is_null() || setter->IsFunctionTemplateInfo() || 438 DCHECK(setter.is_null() || setter->IsFunctionTemplateInfo() ||
389 setter->IsJSFunction()); 439 setter->IsJSFunction());
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
586 Handle<AccessorInfo> accessor(AccessorInfo::cast(array->get(i))); 636 Handle<AccessorInfo> accessor(AccessorInfo::cast(array->get(i)));
587 JSObject::SetAccessor(result, accessor).Assert(); 637 JSObject::SetAccessor(result, accessor).Assert();
588 } 638 }
589 639
590 DCHECK(result->shared()->IsApiFunction()); 640 DCHECK(result->shared()->IsApiFunction());
591 return result; 641 return result;
592 } 642 }
593 643
594 } // namespace internal 644 } // namespace internal
595 } // namespace v8 645 } // namespace v8
OLDNEW
« src/api.cc ('K') | « src/api-natives.h ('k') | src/objects.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698