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

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: review feedback 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
« no previous file with comments | « src/api-natives.h ('k') | test/cctest/cctest.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 const int kSize = 3; 372 const int kSize = 3;
358 PropertyDetails details(attributes, DATA, 0, PropertyCellType::kNoCell); 373 PropertyDetails details(attributes, DATA, 0, PropertyCellType::kNoCell);
359 auto details_handle = handle(details.AsSmi(), isolate); 374 auto details_handle = handle(details.AsSmi(), isolate);
360 Handle<Object> data[kSize] = {name, details_handle, value}; 375 Handle<Object> data[kSize] = {name, details_handle, value};
361 AddPropertyToPropertyList(isolate, info, kSize, data); 376 AddPropertyToPropertyList(isolate, info, kSize, data);
362 } 377 }
363 378
364 379
365 void ApiNatives::AddAccessorProperty(Isolate* isolate, 380 void ApiNatives::AddAccessorProperty(Isolate* isolate,
366 Handle<TemplateInfo> info, 381 Handle<TemplateInfo> info,
367 Handle<Name> name, 382 Handle<Name> name, Handle<Object> getter,
368 Handle<FunctionTemplateInfo> getter, 383 Handle<Object> setter,
369 Handle<FunctionTemplateInfo> setter,
370 PropertyAttributes attributes) { 384 PropertyAttributes attributes) {
385 #ifdef V8_JS_ACCESSORS
386 DCHECK(getter.is_null() || getter->IsFunctionTemplateInfo() ||
387 getter->IsJSFunction());
388 DCHECK(setter.is_null() || setter->IsFunctionTemplateInfo() ||
389 setter->IsJSFunction());
390 #else
391 DCHECK(getter.is_null() || getter->IsFunctionTemplateInfo());
392 DCHECK(setter.is_null() || setter->IsFunctionTemplateInfo());
393 #endif // V8_JS_ACCESSORS
394
371 const int kSize = 4; 395 const int kSize = 4;
372 PropertyDetails details(attributes, ACCESSOR, 0, PropertyCellType::kNoCell); 396 PropertyDetails details(attributes, ACCESSOR, 0, PropertyCellType::kNoCell);
373 auto details_handle = handle(details.AsSmi(), isolate); 397 auto details_handle = handle(details.AsSmi(), isolate);
374 Handle<Object> data[kSize] = {name, details_handle, getter, setter}; 398 Handle<Object> data[kSize] = {name, details_handle, getter, setter};
375 AddPropertyToPropertyList(isolate, info, kSize, data); 399 AddPropertyToPropertyList(isolate, info, kSize, data);
376 } 400 }
377 401
378 402
379 void ApiNatives::AddNativeDataProperty(Isolate* isolate, 403 void ApiNatives::AddNativeDataProperty(Isolate* isolate,
380 Handle<TemplateInfo> info, 404 Handle<TemplateInfo> info,
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
561 Handle<AccessorInfo> accessor(AccessorInfo::cast(array->get(i))); 585 Handle<AccessorInfo> accessor(AccessorInfo::cast(array->get(i)));
562 JSObject::SetAccessor(result, accessor).Assert(); 586 JSObject::SetAccessor(result, accessor).Assert();
563 } 587 }
564 588
565 DCHECK(result->shared()->IsApiFunction()); 589 DCHECK(result->shared()->IsApiFunction());
566 return result; 590 return result;
567 } 591 }
568 592
569 } // namespace internal 593 } // namespace internal
570 } // namespace v8 594 } // namespace v8
OLDNEW
« no previous file with comments | « src/api-natives.h ('k') | test/cctest/cctest.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698