OLD | NEW |
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 Loading... |
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 | |
59 MaybeHandle<Object> DefineAccessorProperty(Isolate* isolate, | 40 MaybeHandle<Object> DefineAccessorProperty(Isolate* isolate, |
60 Handle<JSObject> object, | 41 Handle<JSObject> object, |
61 Handle<Name> name, | 42 Handle<Name> name, |
62 Handle<Object> getter, | 43 Handle<Object> getter, |
63 Handle<Object> setter, | 44 Handle<Object> setter, |
64 PropertyAttributes attributes) { | 45 PropertyAttributes attributes) { |
65 if (!getter->IsUndefined()) { | 46 if (!getter->IsUndefined()) { |
66 ASSIGN_RETURN_ON_EXCEPTION(isolate, getter, | 47 ASSIGN_RETURN_ON_EXCEPTION( |
67 InstantiateFunctionOrMaybeDont(isolate, getter), | 48 isolate, getter, |
68 Object); | 49 InstantiateFunction(isolate, |
| 50 Handle<FunctionTemplateInfo>::cast(getter)), |
| 51 Object); |
69 } | 52 } |
70 if (!setter->IsUndefined()) { | 53 if (!setter->IsUndefined()) { |
71 ASSIGN_RETURN_ON_EXCEPTION(isolate, setter, | 54 ASSIGN_RETURN_ON_EXCEPTION( |
72 InstantiateFunctionOrMaybeDont(isolate, setter), | 55 isolate, setter, |
73 Object); | 56 InstantiateFunction(isolate, |
| 57 Handle<FunctionTemplateInfo>::cast(setter)), |
| 58 Object); |
74 } | 59 } |
75 RETURN_ON_EXCEPTION(isolate, JSObject::DefineAccessor(object, name, getter, | 60 RETURN_ON_EXCEPTION(isolate, JSObject::DefineAccessor(object, name, getter, |
76 setter, attributes), | 61 setter, attributes), |
77 Object); | 62 Object); |
78 return object; | 63 return object; |
79 } | 64 } |
80 | 65 |
81 | 66 |
82 MaybeHandle<Object> DefineDataProperty(Isolate* isolate, | 67 MaybeHandle<Object> DefineDataProperty(Isolate* isolate, |
83 Handle<JSObject> object, | 68 Handle<JSObject> object, |
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
418 auto intrinsic_marker = isolate->factory()->true_value(); | 403 auto intrinsic_marker = isolate->factory()->true_value(); |
419 PropertyDetails details(attributes, DATA, 0, PropertyCellType::kNoCell); | 404 PropertyDetails details(attributes, DATA, 0, PropertyCellType::kNoCell); |
420 auto details_handle = handle(details.AsSmi(), isolate); | 405 auto details_handle = handle(details.AsSmi(), isolate); |
421 Handle<Object> data[kSize] = {name, intrinsic_marker, details_handle, value}; | 406 Handle<Object> data[kSize] = {name, intrinsic_marker, details_handle, value}; |
422 AddPropertyToPropertyList(isolate, info, kSize, data); | 407 AddPropertyToPropertyList(isolate, info, kSize, data); |
423 } | 408 } |
424 | 409 |
425 | 410 |
426 void ApiNatives::AddAccessorProperty(Isolate* isolate, | 411 void ApiNatives::AddAccessorProperty(Isolate* isolate, |
427 Handle<TemplateInfo> info, | 412 Handle<TemplateInfo> info, |
428 Handle<Name> name, Handle<Object> getter, | 413 Handle<Name> name, |
429 Handle<Object> setter, | 414 Handle<FunctionTemplateInfo> getter, |
| 415 Handle<FunctionTemplateInfo> setter, |
430 PropertyAttributes attributes) { | 416 PropertyAttributes attributes) { |
431 #ifdef V8_JS_ACCESSORS | |
432 DCHECK(getter.is_null() || getter->IsFunctionTemplateInfo() || | |
433 getter->IsJSFunction()); | |
434 DCHECK(setter.is_null() || setter->IsFunctionTemplateInfo() || | |
435 setter->IsJSFunction()); | |
436 #else | |
437 DCHECK(getter.is_null() || getter->IsFunctionTemplateInfo()); | |
438 DCHECK(setter.is_null() || setter->IsFunctionTemplateInfo()); | |
439 #endif // V8_JS_ACCESSORS | |
440 | |
441 const int kSize = 4; | 417 const int kSize = 4; |
442 PropertyDetails details(attributes, ACCESSOR, 0, PropertyCellType::kNoCell); | 418 PropertyDetails details(attributes, ACCESSOR, 0, PropertyCellType::kNoCell); |
443 auto details_handle = handle(details.AsSmi(), isolate); | 419 auto details_handle = handle(details.AsSmi(), isolate); |
444 Handle<Object> data[kSize] = {name, details_handle, getter, setter}; | 420 Handle<Object> data[kSize] = {name, details_handle, getter, setter}; |
445 AddPropertyToPropertyList(isolate, info, kSize, data); | 421 AddPropertyToPropertyList(isolate, info, kSize, data); |
446 } | 422 } |
447 | 423 |
448 | 424 |
449 void ApiNatives::AddNativeDataProperty(Isolate* isolate, | 425 void ApiNatives::AddNativeDataProperty(Isolate* isolate, |
450 Handle<TemplateInfo> info, | 426 Handle<TemplateInfo> info, |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
632 Handle<AccessorInfo> accessor(AccessorInfo::cast(array->get(i))); | 608 Handle<AccessorInfo> accessor(AccessorInfo::cast(array->get(i))); |
633 JSObject::SetAccessor(result, accessor).Assert(); | 609 JSObject::SetAccessor(result, accessor).Assert(); |
634 } | 610 } |
635 | 611 |
636 DCHECK(result->shared()->IsApiFunction()); | 612 DCHECK(result->shared()->IsApiFunction()); |
637 return result; | 613 return result; |
638 } | 614 } |
639 | 615 |
640 } // namespace internal | 616 } // namespace internal |
641 } // namespace v8 | 617 } // namespace v8 |
OLD | NEW |