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

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

Issue 1367953002: Allow JavaScript accessors on API objects. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: typo, and/or defective time machine. Created 5 years, 3 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 19 matching lines...) Expand all
30 return InstantiateFunction(isolate, 30 return InstantiateFunction(isolate,
31 Handle<FunctionTemplateInfo>::cast(data), name); 31 Handle<FunctionTemplateInfo>::cast(data), name);
32 } else if (data->IsObjectTemplateInfo()) { 32 } else if (data->IsObjectTemplateInfo()) {
33 return InstantiateObject(isolate, Handle<ObjectTemplateInfo>::cast(data)); 33 return InstantiateObject(isolate, Handle<ObjectTemplateInfo>::cast(data));
34 } else { 34 } else {
35 return data; 35 return data;
36 } 36 }
37 } 37 }
38 38
39 39
40 MaybeHandle<JSFunction> InstantiateFunctionOrMaybeDont(Isolate* isolate,
41 Handle<Object> data) {
42 DCHECK(data->IsFunctionTemplateInfo() || data->IsJSFunction());
43 if (data->IsFunctionTemplateInfo()) {
44 // A function template needs to be instantiated.
45 return InstantiateFunction(isolate,
46 Handle<FunctionTemplateInfo>::cast(data));
47 #ifdef V8_JS_ACCESSORS
48 } else if (data->IsJSFunction()) {
49 // If we already have a proper function, we do not need additional work.
50 // (This should only happen for JavaScript API accessors.)
51 return Handle<JSFunction>::cast(data);
52 #endif // V8_JS_ACCESSORS
53 } else {
54 UNREACHABLE();
55 return MaybeHandle<JSFunction>();
56 }
57 }
58
40 MaybeHandle<Object> DefineAccessorProperty(Isolate* isolate, 59 MaybeHandle<Object> DefineAccessorProperty(Isolate* isolate,
41 Handle<JSObject> object, 60 Handle<JSObject> object,
42 Handle<Name> name, 61 Handle<Name> name,
43 Handle<Object> getter, 62 Handle<Object> getter,
44 Handle<Object> setter, 63 Handle<Object> setter,
45 PropertyAttributes attributes) { 64 PropertyAttributes attributes) {
46 if (!getter->IsUndefined()) { 65 if (!getter->IsUndefined()) {
47 ASSIGN_RETURN_ON_EXCEPTION( 66 ASSIGN_RETURN_ON_EXCEPTION(isolate, getter,
48 isolate, getter, 67 InstantiateFunctionOrMaybeDont(isolate, getter),
49 InstantiateFunction(isolate, 68 Object);
50 Handle<FunctionTemplateInfo>::cast(getter)),
51 Object);
52 } 69 }
53 if (!setter->IsUndefined()) { 70 if (!setter->IsUndefined()) {
54 ASSIGN_RETURN_ON_EXCEPTION( 71 ASSIGN_RETURN_ON_EXCEPTION(isolate, setter,
55 isolate, setter, 72 InstantiateFunctionOrMaybeDont(isolate, setter),
56 InstantiateFunction(isolate, 73 Object);
57 Handle<FunctionTemplateInfo>::cast(setter)),
58 Object);
59 } 74 }
60 RETURN_ON_EXCEPTION(isolate, JSObject::DefineAccessor(object, name, getter, 75 RETURN_ON_EXCEPTION(isolate, JSObject::DefineAccessor(object, name, getter,
61 setter, attributes), 76 setter, attributes),
62 Object); 77 Object);
63 return object; 78 return object;
64 } 79 }
65 80
66 81
67 MaybeHandle<Object> DefineDataProperty(Isolate* isolate, 82 MaybeHandle<Object> DefineDataProperty(Isolate* isolate,
68 Handle<JSObject> object, 83 Handle<JSObject> object,
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 Handle<FunctionTemplateInfo> setter, 384 Handle<FunctionTemplateInfo> setter,
370 PropertyAttributes attributes) { 385 PropertyAttributes attributes) {
371 const int kSize = 4; 386 const int kSize = 4;
372 PropertyDetails details(attributes, ACCESSOR, 0, PropertyCellType::kNoCell); 387 PropertyDetails details(attributes, ACCESSOR, 0, PropertyCellType::kNoCell);
373 auto details_handle = handle(details.AsSmi(), isolate); 388 auto details_handle = handle(details.AsSmi(), isolate);
374 Handle<Object> data[kSize] = {name, details_handle, getter, setter}; 389 Handle<Object> data[kSize] = {name, details_handle, getter, setter};
375 AddPropertyToPropertyList(isolate, info, kSize, data); 390 AddPropertyToPropertyList(isolate, info, kSize, data);
376 } 391 }
377 392
378 393
394 #ifdef V8_JS_ACCESSORS
395 void ApiNatives::AddAccessorProperty(Isolate* isolate,
396 Handle<TemplateInfo> info,
397 Handle<Name> name,
398 Handle<JSFunction> getter,
399 Handle<JSFunction> setter,
400 PropertyAttributes attributes) {
401 const int kSize = 4;
402 PropertyDetails details(attributes, ACCESSOR, 0, PropertyCellType::kNoCell);
403 auto details_handle = handle(details.AsSmi(), isolate);
404 Handle<Object> data[kSize] = {name, details_handle, getter, setter};
405 AddPropertyToPropertyList(isolate, info, kSize, data);
406 }
407 #endif
408
409
379 void ApiNatives::AddNativeDataProperty(Isolate* isolate, 410 void ApiNatives::AddNativeDataProperty(Isolate* isolate,
380 Handle<TemplateInfo> info, 411 Handle<TemplateInfo> info,
381 Handle<AccessorInfo> property) { 412 Handle<AccessorInfo> property) {
382 auto list = handle(info->property_accessors(), isolate); 413 auto list = handle(info->property_accessors(), isolate);
383 if (list->IsUndefined()) { 414 if (list->IsUndefined()) {
384 list = NeanderArray(isolate).value(); 415 list = NeanderArray(isolate).value();
385 info->set_property_accessors(*list); 416 info->set_property_accessors(*list);
386 } 417 }
387 NeanderArray array(list); 418 NeanderArray array(list);
388 array.add(isolate, property); 419 array.add(isolate, property);
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
561 Handle<AccessorInfo> accessor(AccessorInfo::cast(array->get(i))); 592 Handle<AccessorInfo> accessor(AccessorInfo::cast(array->get(i)));
562 JSObject::SetAccessor(result, accessor).Assert(); 593 JSObject::SetAccessor(result, accessor).Assert();
563 } 594 }
564 595
565 DCHECK(result->shared()->IsApiFunction()); 596 DCHECK(result->shared()->IsApiFunction());
566 return result; 597 return result;
567 } 598 }
568 599
569 } // namespace internal 600 } // namespace internal
570 } // namespace v8 601 } // namespace v8
OLDNEW
« src/api-natives.h ('K') | « src/api-natives.h ('k') | test/cctest/cctest.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698