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

Side by Side Diff: src/api.cc

Issue 1542943002: [proxies] Expose proxies in the API (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@2015-12-17_JSProxy_d8_printing_1530293004
Patch Set: adressing comments Created 4 years, 12 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.h ('k') | src/builtins.cc » ('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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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.h" 5 #include "src/api.h"
6 6
7 #include <string.h> // For memcpy, strlen. 7 #include <string.h> // For memcpy, strlen.
8 #ifdef V8_USE_ADDRESS_SANITIZER 8 #ifdef V8_USE_ADDRESS_SANITIZER
9 #include <sanitizer/asan_interface.h> 9 #include <sanitizer/asan_interface.h>
10 #endif // V8_USE_ADDRESS_SANITIZER 10 #endif // V8_USE_ADDRESS_SANITIZER
(...skipping 2760 matching lines...) Expand 10 before | Expand all | Expand 10 after
2771 bool Value::IsObject() const { 2771 bool Value::IsObject() const {
2772 return Utils::OpenHandle(this)->IsJSObject(); 2772 return Utils::OpenHandle(this)->IsJSObject();
2773 } 2773 }
2774 2774
2775 2775
2776 bool Value::IsNumber() const { 2776 bool Value::IsNumber() const {
2777 return Utils::OpenHandle(this)->IsNumber(); 2777 return Utils::OpenHandle(this)->IsNumber();
2778 } 2778 }
2779 2779
2780 2780
2781 bool Value::IsProxy() const { return Utils::OpenHandle(this)->IsJSProxy(); }
2782
2783
2781 #define VALUE_IS_SPECIFIC_TYPE(Type, Class) \ 2784 #define VALUE_IS_SPECIFIC_TYPE(Type, Class) \
2782 bool Value::Is##Type() const { \ 2785 bool Value::Is##Type() const { \
2783 i::Handle<i::Object> obj = Utils::OpenHandle(this); \ 2786 i::Handle<i::Object> obj = Utils::OpenHandle(this); \
2784 if (!obj->IsHeapObject()) return false; \ 2787 if (!obj->IsHeapObject()) return false; \
2785 i::Isolate* isolate = i::HeapObject::cast(*obj)->GetIsolate(); \ 2788 i::Isolate* isolate = i::HeapObject::cast(*obj)->GetIsolate(); \
2786 return obj->HasSpecificClassOf(isolate->heap()->Class##_string()); \ 2789 return obj->HasSpecificClassOf(isolate->heap()->Class##_string()); \
2787 } 2790 }
2788 2791
2789 VALUE_IS_SPECIFIC_TYPE(ArgumentsObject, Arguments) 2792 VALUE_IS_SPECIFIC_TYPE(ArgumentsObject, Arguments)
2790 VALUE_IS_SPECIFIC_TYPE(BooleanObject, Boolean) 2793 VALUE_IS_SPECIFIC_TYPE(BooleanObject, Boolean)
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
2876 bool Value::IsMapIterator() const { 2879 bool Value::IsMapIterator() const {
2877 return Utils::OpenHandle(this)->IsJSMapIterator(); 2880 return Utils::OpenHandle(this)->IsJSMapIterator();
2878 } 2881 }
2879 2882
2880 2883
2881 bool Value::IsSetIterator() const { 2884 bool Value::IsSetIterator() const {
2882 return Utils::OpenHandle(this)->IsJSSetIterator(); 2885 return Utils::OpenHandle(this)->IsJSSetIterator();
2883 } 2886 }
2884 2887
2885 2888
2889 bool Value::IsPromise() const {
2890 auto self = Utils::OpenHandle(this);
2891 return i::Object::IsPromise(self);
2892 }
2893
2894
2886 MaybeLocal<String> Value::ToString(Local<Context> context) const { 2895 MaybeLocal<String> Value::ToString(Local<Context> context) const {
2887 auto obj = Utils::OpenHandle(this); 2896 auto obj = Utils::OpenHandle(this);
2888 if (obj->IsString()) return ToApiHandle<String>(obj); 2897 if (obj->IsString()) return ToApiHandle<String>(obj);
2889 PREPARE_FOR_EXECUTION(context, "ToString", String); 2898 PREPARE_FOR_EXECUTION(context, "ToString", String);
2890 Local<String> result; 2899 Local<String> result;
2891 has_pending_exception = 2900 has_pending_exception =
2892 !ToLocal<String>(i::Object::ToString(isolate, obj), &result); 2901 !ToLocal<String>(i::Object::ToString(isolate, obj), &result);
2893 RETURN_ON_FAILED_EXECUTION(String); 2902 RETURN_ON_FAILED_EXECUTION(String);
2894 RETURN_ESCAPED(result); 2903 RETURN_ESCAPED(result);
2895 } 2904 }
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
3139 } 3148 }
3140 3149
3141 3150
3142 void v8::Promise::Resolver::CheckCast(Value* that) { 3151 void v8::Promise::Resolver::CheckCast(Value* that) {
3143 Utils::ApiCheck(that->IsPromise(), 3152 Utils::ApiCheck(that->IsPromise(),
3144 "v8::Promise::Resolver::Cast()", 3153 "v8::Promise::Resolver::Cast()",
3145 "Could not convert to promise resolver"); 3154 "Could not convert to promise resolver");
3146 } 3155 }
3147 3156
3148 3157
3158 void v8::Proxy::CheckCast(Value* that) {
3159 Utils::ApiCheck(that->IsProxy(), "v8::Proxy::Cast()",
3160 "Could not convert to proxy");
3161 }
3162
3163
3149 void v8::ArrayBuffer::CheckCast(Value* that) { 3164 void v8::ArrayBuffer::CheckCast(Value* that) {
3150 i::Handle<i::Object> obj = Utils::OpenHandle(that); 3165 i::Handle<i::Object> obj = Utils::OpenHandle(that);
3151 Utils::ApiCheck( 3166 Utils::ApiCheck(
3152 obj->IsJSArrayBuffer() && !i::JSArrayBuffer::cast(*obj)->is_shared(), 3167 obj->IsJSArrayBuffer() && !i::JSArrayBuffer::cast(*obj)->is_shared(),
3153 "v8::ArrayBuffer::Cast()", "Could not convert to ArrayBuffer"); 3168 "v8::ArrayBuffer::Cast()", "Could not convert to ArrayBuffer");
3154 } 3169 }
3155 3170
3156 3171
3157 void v8::ArrayBufferView::CheckCast(Value* that) { 3172 void v8::ArrayBufferView::CheckCast(Value* that) {
3158 i::Handle<i::Object> obj = Utils::OpenHandle(that); 3173 i::Handle<i::Object> obj = Utils::OpenHandle(that);
(...skipping 3180 matching lines...) Expand 10 before | Expand all | Expand 10 after
6339 if (!key->IsTheHole()) { 6354 if (!key->IsTheHole()) {
6340 result->set(i, key); 6355 result->set(i, key);
6341 } 6356 }
6342 } 6357 }
6343 i::Handle<i::JSArray> result_array = 6358 i::Handle<i::JSArray> result_array =
6344 factory->NewJSArrayWithElements(result, i::FAST_ELEMENTS, length); 6359 factory->NewJSArrayWithElements(result, i::FAST_ELEMENTS, length);
6345 return Utils::ToLocal(result_array); 6360 return Utils::ToLocal(result_array);
6346 } 6361 }
6347 6362
6348 6363
6349 bool Value::IsPromise() const {
6350 auto self = Utils::OpenHandle(this);
6351 return i::Object::IsPromise(self);
6352 }
6353
6354
6355 MaybeLocal<Promise::Resolver> Promise::Resolver::New(Local<Context> context) { 6364 MaybeLocal<Promise::Resolver> Promise::Resolver::New(Local<Context> context) {
6356 PREPARE_FOR_EXECUTION(context, "Promise::Resolver::New", Resolver); 6365 PREPARE_FOR_EXECUTION(context, "Promise::Resolver::New", Resolver);
6357 i::Handle<i::Object> result; 6366 i::Handle<i::Object> result;
6358 has_pending_exception = 6367 has_pending_exception =
6359 !i::Execution::Call(isolate, isolate->promise_create(), 6368 !i::Execution::Call(isolate, isolate->promise_create(),
6360 isolate->factory()->undefined_value(), 0, NULL) 6369 isolate->factory()->undefined_value(), 0, NULL)
6361 .ToHandle(&result); 6370 .ToHandle(&result);
6362 RETURN_ON_FAILED_EXECUTION(Promise::Resolver); 6371 RETURN_ON_FAILED_EXECUTION(Promise::Resolver);
6363 RETURN_ESCAPED(Local<Promise::Resolver>::Cast(Utils::ToLocal(result))); 6372 RETURN_ESCAPED(Local<Promise::Resolver>::Cast(Utils::ToLocal(result)));
6364 } 6373 }
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
6491 bool Promise::HasHandler() { 6500 bool Promise::HasHandler() {
6492 i::Handle<i::JSReceiver> promise = Utils::OpenHandle(this); 6501 i::Handle<i::JSReceiver> promise = Utils::OpenHandle(this);
6493 i::Isolate* isolate = promise->GetIsolate(); 6502 i::Isolate* isolate = promise->GetIsolate();
6494 LOG_API(isolate, "Promise::HasRejectHandler"); 6503 LOG_API(isolate, "Promise::HasRejectHandler");
6495 ENTER_V8(isolate); 6504 ENTER_V8(isolate);
6496 i::Handle<i::Symbol> key = isolate->factory()->promise_has_handler_symbol(); 6505 i::Handle<i::Symbol> key = isolate->factory()->promise_has_handler_symbol();
6497 return i::JSReceiver::GetDataProperty(promise, key)->IsTrue(); 6506 return i::JSReceiver::GetDataProperty(promise, key)->IsTrue();
6498 } 6507 }
6499 6508
6500 6509
6510 Local<Object> Proxy::GetTarget() {
6511 i::Handle<i::JSProxy> self = Utils::OpenHandle(this);
6512 i::Handle<i::JSReceiver> target(self->target());
6513 return Utils::ToLocal(target);
6514 }
6515
6516
6517 Local<Value> Proxy::GetHandler() {
6518 i::Handle<i::JSProxy> self = Utils::OpenHandle(this);
6519 i::Handle<i::Object> handler(self->handler(), self->GetIsolate());
6520 return Utils::ToLocal(handler);
6521 }
6522
6523
6524 bool Proxy::IsRevoked() {
6525 i::Handle<i::JSProxy> self = Utils::OpenHandle(this);
6526 return self->IsRevoked();
6527 }
6528
6529
6530 void Proxy::Revoke() {
6531 i::Handle<i::JSProxy> self = Utils::OpenHandle(this);
6532 i::JSProxy::Revoke(self);
6533 }
6534
6535
6536 MaybeLocal<Proxy> Proxy::New(Local<Context> context, Local<Object> local_target,
6537 Local<Object> local_handler) {
6538 PREPARE_FOR_EXECUTION(context, "Proxy::New", Proxy);
6539 i::Handle<i::JSReceiver> target = Utils::OpenHandle(*local_target);
6540 i::Handle<i::JSReceiver> handler = Utils::OpenHandle(*local_handler);
6541 Local<Proxy> result;
6542 has_pending_exception =
6543 !ToLocal<Proxy>(i::JSProxy::New(isolate, target, handler), &result);
6544 RETURN_ON_FAILED_EXECUTION(Proxy);
6545 RETURN_ESCAPED(result);
6546 }
6547
6501 bool v8::ArrayBuffer::IsExternal() const { 6548 bool v8::ArrayBuffer::IsExternal() const {
6502 return Utils::OpenHandle(this)->is_external(); 6549 return Utils::OpenHandle(this)->is_external();
6503 } 6550 }
6504 6551
6505 6552
6506 bool v8::ArrayBuffer::IsNeuterable() const { 6553 bool v8::ArrayBuffer::IsNeuterable() const {
6507 return Utils::OpenHandle(this)->is_neuterable(); 6554 return Utils::OpenHandle(this)->is_neuterable();
6508 } 6555 }
6509 6556
6510 6557
(...skipping 1981 matching lines...) Expand 10 before | Expand all | Expand 10 after
8492 Address callback_address = 8539 Address callback_address =
8493 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); 8540 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback));
8494 VMState<EXTERNAL> state(isolate); 8541 VMState<EXTERNAL> state(isolate);
8495 ExternalCallbackScope call_scope(isolate, callback_address); 8542 ExternalCallbackScope call_scope(isolate, callback_address);
8496 callback(info); 8543 callback(info);
8497 } 8544 }
8498 8545
8499 8546
8500 } // namespace internal 8547 } // namespace internal
8501 } // namespace v8 8548 } // namespace v8
OLDNEW
« no previous file with comments | « src/api.h ('k') | src/builtins.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698