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

Side by Side Diff: src/api.cc

Issue 669373002: pass isolate to Value::To* functions (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: rebase Created 6 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « include/v8.h ('k') | src/d8.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 2562 matching lines...) Expand 10 before | Expand all | Expand 10 after
2573 i::Handle<i::JSFunction> func = i::Handle<i::JSFunction>::cast(obj); 2573 i::Handle<i::JSFunction> func = i::Handle<i::JSFunction>::cast(obj);
2574 return func->shared()->is_generator(); 2574 return func->shared()->is_generator();
2575 } 2575 }
2576 2576
2577 2577
2578 bool Value::IsGeneratorObject() const { 2578 bool Value::IsGeneratorObject() const {
2579 return Utils::OpenHandle(this)->IsJSGeneratorObject(); 2579 return Utils::OpenHandle(this)->IsJSGeneratorObject();
2580 } 2580 }
2581 2581
2582 2582
2583 Local<String> Value::ToString() const { 2583 Local<String> Value::ToString(Isolate* v8_isolate) const {
2584 i::Handle<i::Object> obj = Utils::OpenHandle(this); 2584 i::Handle<i::Object> obj = Utils::OpenHandle(this);
2585 i::Handle<i::Object> str; 2585 i::Handle<i::Object> str;
2586 if (obj->IsString()) { 2586 if (obj->IsString()) {
2587 str = obj; 2587 str = obj;
2588 } else { 2588 } else {
2589 i::Isolate* isolate = i::Isolate::Current(); 2589 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
2590 LOG_API(isolate, "ToString"); 2590 LOG_API(isolate, "ToString");
2591 ENTER_V8(isolate); 2591 ENTER_V8(isolate);
2592 EXCEPTION_PREAMBLE(isolate); 2592 EXCEPTION_PREAMBLE(isolate);
2593 has_pending_exception = !i::Execution::ToString( 2593 has_pending_exception = !i::Execution::ToString(
2594 isolate, obj).ToHandle(&str); 2594 isolate, obj).ToHandle(&str);
2595 EXCEPTION_BAILOUT_CHECK(isolate, Local<String>()); 2595 EXCEPTION_BAILOUT_CHECK(isolate, Local<String>());
2596 } 2596 }
2597 return ToApiHandle<String>(str); 2597 return ToApiHandle<String>(str);
2598 } 2598 }
2599 2599
2600 2600
2601 Local<String> Value::ToDetailString() const { 2601 Local<String> Value::ToDetailString(Isolate* v8_isolate) const {
2602 i::Handle<i::Object> obj = Utils::OpenHandle(this); 2602 i::Handle<i::Object> obj = Utils::OpenHandle(this);
2603 i::Handle<i::Object> str; 2603 i::Handle<i::Object> str;
2604 if (obj->IsString()) { 2604 if (obj->IsString()) {
2605 str = obj; 2605 str = obj;
2606 } else { 2606 } else {
2607 i::Isolate* isolate = i::Isolate::Current(); 2607 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
2608 LOG_API(isolate, "ToDetailString"); 2608 LOG_API(isolate, "ToDetailString");
2609 ENTER_V8(isolate); 2609 ENTER_V8(isolate);
2610 EXCEPTION_PREAMBLE(isolate); 2610 EXCEPTION_PREAMBLE(isolate);
2611 has_pending_exception = !i::Execution::ToDetailString( 2611 has_pending_exception = !i::Execution::ToDetailString(
2612 isolate, obj).ToHandle(&str); 2612 isolate, obj).ToHandle(&str);
2613 EXCEPTION_BAILOUT_CHECK(isolate, Local<String>()); 2613 EXCEPTION_BAILOUT_CHECK(isolate, Local<String>());
2614 } 2614 }
2615 return ToApiHandle<String>(str); 2615 return ToApiHandle<String>(str);
2616 } 2616 }
2617 2617
2618 2618
2619 Local<v8::Object> Value::ToObject() const { 2619 Local<v8::Object> Value::ToObject(Isolate* v8_isolate) const {
2620 i::Handle<i::Object> obj = Utils::OpenHandle(this); 2620 i::Handle<i::Object> obj = Utils::OpenHandle(this);
2621 i::Handle<i::Object> val; 2621 i::Handle<i::Object> val;
2622 if (obj->IsJSObject()) { 2622 if (obj->IsJSObject()) {
2623 val = obj; 2623 val = obj;
2624 } else { 2624 } else {
2625 i::Isolate* isolate = i::Isolate::Current(); 2625 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
2626 LOG_API(isolate, "ToObject"); 2626 LOG_API(isolate, "ToObject");
2627 ENTER_V8(isolate); 2627 ENTER_V8(isolate);
2628 EXCEPTION_PREAMBLE(isolate); 2628 EXCEPTION_PREAMBLE(isolate);
2629 has_pending_exception = !i::Execution::ToObject( 2629 has_pending_exception = !i::Execution::ToObject(
2630 isolate, obj).ToHandle(&val); 2630 isolate, obj).ToHandle(&val);
2631 EXCEPTION_BAILOUT_CHECK(isolate, Local<v8::Object>()); 2631 EXCEPTION_BAILOUT_CHECK(isolate, Local<v8::Object>());
2632 } 2632 }
2633 return ToApiHandle<Object>(val); 2633 return ToApiHandle<Object>(val);
2634 } 2634 }
2635 2635
2636 2636
2637 Local<Boolean> Value::ToBoolean() const { 2637 Local<Boolean> Value::ToBoolean(Isolate* v8_isolate) const {
2638 i::Handle<i::Object> obj = Utils::OpenHandle(this); 2638 i::Handle<i::Object> obj = Utils::OpenHandle(this);
2639 if (obj->IsBoolean()) { 2639 if (obj->IsBoolean()) {
2640 return ToApiHandle<Boolean>(obj); 2640 return ToApiHandle<Boolean>(obj);
2641 } else { 2641 } else {
2642 i::Isolate* isolate = i::Isolate::Current(); 2642 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
2643 LOG_API(isolate, "ToBoolean"); 2643 LOG_API(isolate, "ToBoolean");
2644 ENTER_V8(isolate); 2644 ENTER_V8(isolate);
2645 i::Handle<i::Object> val = 2645 i::Handle<i::Object> val =
2646 isolate->factory()->ToBoolean(obj->BooleanValue()); 2646 isolate->factory()->ToBoolean(obj->BooleanValue());
2647 return ToApiHandle<Boolean>(val); 2647 return ToApiHandle<Boolean>(val);
2648 } 2648 }
2649 } 2649 }
2650 2650
2651 2651
2652 Local<Number> Value::ToNumber() const { 2652 Local<Number> Value::ToNumber(Isolate* v8_isolate) const {
2653 i::Handle<i::Object> obj = Utils::OpenHandle(this); 2653 i::Handle<i::Object> obj = Utils::OpenHandle(this);
2654 i::Handle<i::Object> num; 2654 i::Handle<i::Object> num;
2655 if (obj->IsNumber()) { 2655 if (obj->IsNumber()) {
2656 num = obj; 2656 num = obj;
2657 } else { 2657 } else {
2658 i::Isolate* isolate = i::HeapObject::cast(*obj)->GetIsolate(); 2658 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
2659 LOG_API(isolate, "ToNumber"); 2659 LOG_API(isolate, "ToNumber");
2660 ENTER_V8(isolate); 2660 ENTER_V8(isolate);
2661 EXCEPTION_PREAMBLE(isolate); 2661 EXCEPTION_PREAMBLE(isolate);
2662 has_pending_exception = !i::Execution::ToNumber( 2662 has_pending_exception = !i::Execution::ToNumber(
2663 isolate, obj).ToHandle(&num); 2663 isolate, obj).ToHandle(&num);
2664 EXCEPTION_BAILOUT_CHECK(isolate, Local<Number>()); 2664 EXCEPTION_BAILOUT_CHECK(isolate, Local<Number>());
2665 } 2665 }
2666 return ToApiHandle<Number>(num); 2666 return ToApiHandle<Number>(num);
2667 } 2667 }
2668 2668
2669 2669
2670 Local<Integer> Value::ToInteger() const { 2670 Local<Integer> Value::ToInteger(Isolate* v8_isolate) const {
2671 i::Handle<i::Object> obj = Utils::OpenHandle(this); 2671 i::Handle<i::Object> obj = Utils::OpenHandle(this);
2672 i::Handle<i::Object> num; 2672 i::Handle<i::Object> num;
2673 if (obj->IsSmi()) { 2673 if (obj->IsSmi()) {
2674 num = obj; 2674 num = obj;
2675 } else { 2675 } else {
2676 i::Isolate* isolate = i::HeapObject::cast(*obj)->GetIsolate(); 2676 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
2677 LOG_API(isolate, "ToInteger"); 2677 LOG_API(isolate, "ToInteger");
2678 ENTER_V8(isolate); 2678 ENTER_V8(isolate);
2679 EXCEPTION_PREAMBLE(isolate); 2679 EXCEPTION_PREAMBLE(isolate);
2680 has_pending_exception = !i::Execution::ToInteger( 2680 has_pending_exception = !i::Execution::ToInteger(
2681 isolate, obj).ToHandle(&num); 2681 isolate, obj).ToHandle(&num);
2682 EXCEPTION_BAILOUT_CHECK(isolate, Local<Integer>()); 2682 EXCEPTION_BAILOUT_CHECK(isolate, Local<Integer>());
2683 } 2683 }
2684 return ToApiHandle<Integer>(num); 2684 return ToApiHandle<Integer>(num);
2685 } 2685 }
2686 2686
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
2928 EXCEPTION_BAILOUT_CHECK(isolate, 0); 2928 EXCEPTION_BAILOUT_CHECK(isolate, 0);
2929 } 2929 }
2930 if (num->IsSmi()) { 2930 if (num->IsSmi()) {
2931 return i::Smi::cast(*num)->value(); 2931 return i::Smi::cast(*num)->value();
2932 } else { 2932 } else {
2933 return static_cast<int64_t>(num->Number()); 2933 return static_cast<int64_t>(num->Number());
2934 } 2934 }
2935 } 2935 }
2936 2936
2937 2937
2938 Local<Int32> Value::ToInt32() const { 2938 Local<Int32> Value::ToInt32(Isolate* v8_isolate) const {
2939 i::Handle<i::Object> obj = Utils::OpenHandle(this); 2939 i::Handle<i::Object> obj = Utils::OpenHandle(this);
2940 i::Handle<i::Object> num; 2940 i::Handle<i::Object> num;
2941 if (obj->IsSmi()) { 2941 if (obj->IsSmi()) {
2942 num = obj; 2942 num = obj;
2943 } else { 2943 } else {
2944 i::Isolate* isolate = i::HeapObject::cast(*obj)->GetIsolate(); 2944 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
2945 LOG_API(isolate, "ToInt32"); 2945 LOG_API(isolate, "ToInt32");
2946 ENTER_V8(isolate); 2946 ENTER_V8(isolate);
2947 EXCEPTION_PREAMBLE(isolate); 2947 EXCEPTION_PREAMBLE(isolate);
2948 has_pending_exception = !i::Execution::ToInt32(isolate, obj).ToHandle(&num); 2948 has_pending_exception = !i::Execution::ToInt32(isolate, obj).ToHandle(&num);
2949 EXCEPTION_BAILOUT_CHECK(isolate, Local<Int32>()); 2949 EXCEPTION_BAILOUT_CHECK(isolate, Local<Int32>());
2950 } 2950 }
2951 return ToApiHandle<Int32>(num); 2951 return ToApiHandle<Int32>(num);
2952 } 2952 }
2953 2953
2954 2954
2955 Local<Uint32> Value::ToUint32() const { 2955 Local<Uint32> Value::ToUint32(Isolate* v8_isolate) const {
2956 i::Handle<i::Object> obj = Utils::OpenHandle(this); 2956 i::Handle<i::Object> obj = Utils::OpenHandle(this);
2957 i::Handle<i::Object> num; 2957 i::Handle<i::Object> num;
2958 if (obj->IsSmi()) { 2958 if (obj->IsSmi()) {
2959 num = obj; 2959 num = obj;
2960 } else { 2960 } else {
2961 i::Isolate* isolate = i::HeapObject::cast(*obj)->GetIsolate(); 2961 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
2962 LOG_API(isolate, "ToUInt32"); 2962 LOG_API(isolate, "ToUInt32");
2963 ENTER_V8(isolate); 2963 ENTER_V8(isolate);
2964 EXCEPTION_PREAMBLE(isolate); 2964 EXCEPTION_PREAMBLE(isolate);
2965 has_pending_exception = !i::Execution::ToUint32( 2965 has_pending_exception = !i::Execution::ToUint32(
2966 isolate, obj).ToHandle(&num); 2966 isolate, obj).ToHandle(&num);
2967 EXCEPTION_BAILOUT_CHECK(isolate, Local<Uint32>()); 2967 EXCEPTION_BAILOUT_CHECK(isolate, Local<Uint32>());
2968 } 2968 }
2969 return ToApiHandle<Uint32>(num); 2969 return ToApiHandle<Uint32>(num);
2970 } 2970 }
2971 2971
(...skipping 3937 matching lines...) Expand 10 before | Expand all | Expand 10 after
6909 } 6909 }
6910 6910
6911 6911
6912 String::Utf8Value::Utf8Value(v8::Handle<v8::Value> obj) 6912 String::Utf8Value::Utf8Value(v8::Handle<v8::Value> obj)
6913 : str_(NULL), length_(0) { 6913 : str_(NULL), length_(0) {
6914 i::Isolate* isolate = i::Isolate::Current(); 6914 i::Isolate* isolate = i::Isolate::Current();
6915 if (obj.IsEmpty()) return; 6915 if (obj.IsEmpty()) return;
6916 ENTER_V8(isolate); 6916 ENTER_V8(isolate);
6917 i::HandleScope scope(isolate); 6917 i::HandleScope scope(isolate);
6918 TryCatch try_catch; 6918 TryCatch try_catch;
6919 Handle<String> str = obj->ToString(); 6919 Handle<String> str = obj->ToString(reinterpret_cast<v8::Isolate*>(isolate));
6920 if (str.IsEmpty()) return; 6920 if (str.IsEmpty()) return;
6921 i::Handle<i::String> i_str = Utils::OpenHandle(*str); 6921 i::Handle<i::String> i_str = Utils::OpenHandle(*str);
6922 length_ = v8::Utf8Length(*i_str, isolate); 6922 length_ = v8::Utf8Length(*i_str, isolate);
6923 str_ = i::NewArray<char>(length_ + 1); 6923 str_ = i::NewArray<char>(length_ + 1);
6924 str->WriteUtf8(str_); 6924 str->WriteUtf8(str_);
6925 } 6925 }
6926 6926
6927 6927
6928 String::Utf8Value::~Utf8Value() { 6928 String::Utf8Value::~Utf8Value() {
6929 i::DeleteArray(str_); 6929 i::DeleteArray(str_);
6930 } 6930 }
6931 6931
6932 6932
6933 String::Value::Value(v8::Handle<v8::Value> obj) 6933 String::Value::Value(v8::Handle<v8::Value> obj)
6934 : str_(NULL), length_(0) { 6934 : str_(NULL), length_(0) {
6935 i::Isolate* isolate = i::Isolate::Current(); 6935 i::Isolate* isolate = i::Isolate::Current();
6936 if (obj.IsEmpty()) return; 6936 if (obj.IsEmpty()) return;
6937 ENTER_V8(isolate); 6937 ENTER_V8(isolate);
6938 i::HandleScope scope(isolate); 6938 i::HandleScope scope(isolate);
6939 TryCatch try_catch; 6939 TryCatch try_catch;
6940 Handle<String> str = obj->ToString(); 6940 Handle<String> str = obj->ToString(reinterpret_cast<v8::Isolate*>(isolate));
6941 if (str.IsEmpty()) return; 6941 if (str.IsEmpty()) return;
6942 length_ = str->Length(); 6942 length_ = str->Length();
6943 str_ = i::NewArray<uint16_t>(length_ + 1); 6943 str_ = i::NewArray<uint16_t>(length_ + 1);
6944 str->Write(str_); 6944 str->Write(str_);
6945 } 6945 }
6946 6946
6947 6947
6948 String::Value::~Value() { 6948 String::Value::~Value() {
6949 i::DeleteArray(str_); 6949 i::DeleteArray(str_);
6950 } 6950 }
(...skipping 814 matching lines...) Expand 10 before | Expand all | Expand 10 after
7765 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); 7765 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate());
7766 Address callback_address = 7766 Address callback_address =
7767 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); 7767 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback));
7768 VMState<EXTERNAL> state(isolate); 7768 VMState<EXTERNAL> state(isolate);
7769 ExternalCallbackScope call_scope(isolate, callback_address); 7769 ExternalCallbackScope call_scope(isolate, callback_address);
7770 callback(info); 7770 callback(info);
7771 } 7771 }
7772 7772
7773 7773
7774 } } // namespace v8::internal 7774 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « include/v8.h ('k') | src/d8.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698