From: dcarney@chromium.org Date: Mon, 27 Oct 2014 09:02:49 +0000 (+0000) Subject: pass isolate to Value::To* functions X-Git-Tag: upstream/4.7.83~6105 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b714772c07fdb2fbb337557658bcea713d051a0f;p=platform%2Fupstream%2Fv8.git pass isolate to Value::To* functions BUG= R=svenpanne@chromium.org Review URL: https://codereview.chromium.org/669373002 Cr-Commit-Position: refs/heads/master@{#24893} git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@24893 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- diff --git a/include/v8.h b/include/v8.h index f8519db..f70f457 100644 --- a/include/v8.h +++ b/include/v8.h @@ -1703,14 +1703,24 @@ class V8_EXPORT Value : public Data { */ bool IsDataView() const; - Local ToBoolean() const; - Local ToNumber() const; - Local ToString() const; - Local ToDetailString() const; - Local ToObject() const; - Local ToInteger() const; - Local ToUint32() const; - Local ToInt32() const; + Local ToBoolean(Isolate* isolate) const; + Local ToNumber(Isolate* isolate) const; + Local ToString(Isolate* isolate) const; + Local ToDetailString(Isolate* isolate) const; + Local ToObject(Isolate* isolate) const; + Local ToInteger(Isolate* isolate) const; + Local ToUint32(Isolate* isolate) const; + Local ToInt32(Isolate* isolate) const; + + // TODO(dcarney): deprecate all these. + inline Local ToBoolean() const; + inline Local ToNumber() const; + inline Local ToString() const; + inline Local ToDetailString() const; + inline Local ToObject() const; + inline Local ToInteger() const; + inline Local ToUint32() const; + inline Local ToInt32() const; /** * Attempts to convert a string to an array index. @@ -6638,6 +6648,44 @@ template Value* Value::Cast(T* value) { } +Local Value::ToBoolean() const { + return ToBoolean(Isolate::GetCurrent()); +} + + +Local Value::ToNumber() const { + return ToNumber(Isolate::GetCurrent()); +} + + +Local Value::ToString() const { + return ToString(Isolate::GetCurrent()); +} + + +Local Value::ToDetailString() const { + return ToDetailString(Isolate::GetCurrent()); +} + + +Local Value::ToObject() const { + return ToObject(Isolate::GetCurrent()); +} + + +Local Value::ToInteger() const { + return ToInteger(Isolate::GetCurrent()); +} + + +Local Value::ToUint32() const { + return ToUint32(Isolate::GetCurrent()); +} + + +Local Value::ToInt32() const { return ToInt32(Isolate::GetCurrent()); } + + Name* Name::Cast(v8::Value* value) { #ifdef V8_ENABLE_CHECKS CheckCast(value); diff --git a/src/api.cc b/src/api.cc index 1698a3e..909335d 100644 --- a/src/api.cc +++ b/src/api.cc @@ -2580,13 +2580,13 @@ bool Value::IsGeneratorObject() const { } -Local Value::ToString() const { +Local Value::ToString(Isolate* v8_isolate) const { i::Handle obj = Utils::OpenHandle(this); i::Handle str; if (obj->IsString()) { str = obj; } else { - i::Isolate* isolate = i::Isolate::Current(); + i::Isolate* isolate = reinterpret_cast(v8_isolate); LOG_API(isolate, "ToString"); ENTER_V8(isolate); EXCEPTION_PREAMBLE(isolate); @@ -2598,13 +2598,13 @@ Local Value::ToString() const { } -Local Value::ToDetailString() const { +Local Value::ToDetailString(Isolate* v8_isolate) const { i::Handle obj = Utils::OpenHandle(this); i::Handle str; if (obj->IsString()) { str = obj; } else { - i::Isolate* isolate = i::Isolate::Current(); + i::Isolate* isolate = reinterpret_cast(v8_isolate); LOG_API(isolate, "ToDetailString"); ENTER_V8(isolate); EXCEPTION_PREAMBLE(isolate); @@ -2616,13 +2616,13 @@ Local Value::ToDetailString() const { } -Local Value::ToObject() const { +Local Value::ToObject(Isolate* v8_isolate) const { i::Handle obj = Utils::OpenHandle(this); i::Handle val; if (obj->IsJSObject()) { val = obj; } else { - i::Isolate* isolate = i::Isolate::Current(); + i::Isolate* isolate = reinterpret_cast(v8_isolate); LOG_API(isolate, "ToObject"); ENTER_V8(isolate); EXCEPTION_PREAMBLE(isolate); @@ -2634,12 +2634,12 @@ Local Value::ToObject() const { } -Local Value::ToBoolean() const { +Local Value::ToBoolean(Isolate* v8_isolate) const { i::Handle obj = Utils::OpenHandle(this); if (obj->IsBoolean()) { return ToApiHandle(obj); } else { - i::Isolate* isolate = i::Isolate::Current(); + i::Isolate* isolate = reinterpret_cast(v8_isolate); LOG_API(isolate, "ToBoolean"); ENTER_V8(isolate); i::Handle val = @@ -2649,13 +2649,13 @@ Local Value::ToBoolean() const { } -Local Value::ToNumber() const { +Local Value::ToNumber(Isolate* v8_isolate) const { i::Handle obj = Utils::OpenHandle(this); i::Handle num; if (obj->IsNumber()) { num = obj; } else { - i::Isolate* isolate = i::HeapObject::cast(*obj)->GetIsolate(); + i::Isolate* isolate = reinterpret_cast(v8_isolate); LOG_API(isolate, "ToNumber"); ENTER_V8(isolate); EXCEPTION_PREAMBLE(isolate); @@ -2667,13 +2667,13 @@ Local Value::ToNumber() const { } -Local Value::ToInteger() const { +Local Value::ToInteger(Isolate* v8_isolate) const { i::Handle obj = Utils::OpenHandle(this); i::Handle num; if (obj->IsSmi()) { num = obj; } else { - i::Isolate* isolate = i::HeapObject::cast(*obj)->GetIsolate(); + i::Isolate* isolate = reinterpret_cast(v8_isolate); LOG_API(isolate, "ToInteger"); ENTER_V8(isolate); EXCEPTION_PREAMBLE(isolate); @@ -2935,13 +2935,13 @@ int64_t Value::IntegerValue() const { } -Local Value::ToInt32() const { +Local Value::ToInt32(Isolate* v8_isolate) const { i::Handle obj = Utils::OpenHandle(this); i::Handle num; if (obj->IsSmi()) { num = obj; } else { - i::Isolate* isolate = i::HeapObject::cast(*obj)->GetIsolate(); + i::Isolate* isolate = reinterpret_cast(v8_isolate); LOG_API(isolate, "ToInt32"); ENTER_V8(isolate); EXCEPTION_PREAMBLE(isolate); @@ -2952,13 +2952,13 @@ Local Value::ToInt32() const { } -Local Value::ToUint32() const { +Local Value::ToUint32(Isolate* v8_isolate) const { i::Handle obj = Utils::OpenHandle(this); i::Handle num; if (obj->IsSmi()) { num = obj; } else { - i::Isolate* isolate = i::HeapObject::cast(*obj)->GetIsolate(); + i::Isolate* isolate = reinterpret_cast(v8_isolate); LOG_API(isolate, "ToUInt32"); ENTER_V8(isolate); EXCEPTION_PREAMBLE(isolate); @@ -6916,7 +6916,7 @@ String::Utf8Value::Utf8Value(v8::Handle obj) ENTER_V8(isolate); i::HandleScope scope(isolate); TryCatch try_catch; - Handle str = obj->ToString(); + Handle str = obj->ToString(reinterpret_cast(isolate)); if (str.IsEmpty()) return; i::Handle i_str = Utils::OpenHandle(*str); length_ = v8::Utf8Length(*i_str, isolate); @@ -6937,7 +6937,7 @@ String::Value::Value(v8::Handle obj) ENTER_V8(isolate); i::HandleScope scope(isolate); TryCatch try_catch; - Handle str = obj->ToString(); + Handle str = obj->ToString(reinterpret_cast(isolate)); if (str.IsEmpty()) return; length_ = str->Length(); str_ = i::NewArray(length_ + 1); diff --git a/src/d8-debug.cc b/src/d8-debug.cc index 71e006c..7032415 100644 --- a/src/d8-debug.cc +++ b/src/d8-debug.cc @@ -124,7 +124,7 @@ void HandleDebugEvent(const Debug::EventDetails& event_details) { printf("%s\n", *text_str); } running = response_details->Get(String::NewFromUtf8(isolate, "running")) - ->ToBoolean() + ->ToBoolean(isolate) ->Value(); } } diff --git a/src/d8.cc b/src/d8.cc index 85d1048..fb24bcc 100644 --- a/src/d8.cc +++ b/src/d8.cc @@ -186,7 +186,7 @@ ScriptCompiler::CachedData* CompileForCachedData( int name_length = 0; uint16_t* name_buffer = NULL; if (name->IsString()) { - Local name_string = name->ToString(); + Local name_string = Local::Cast(name); name_length = name_string->Length(); name_buffer = new uint16_t[name_length]; name_string->Write(name_buffer, 0, name_length); @@ -410,7 +410,7 @@ void Shell::RealmOwner(const v8::FunctionCallbackInfo& args) { Throw(args.GetIsolate(), "Invalid argument"); return; } - int index = data->RealmFind(args[0]->ToObject()->CreationContext()); + int index = data->RealmFind(args[0]->ToObject(isolate)->CreationContext()); if (index == -1) return; args.GetReturnValue().Set(index); } @@ -480,7 +480,7 @@ void Shell::RealmEval(const v8::FunctionCallbackInfo& args) { Throw(args.GetIsolate(), "Invalid argument"); return; } - ScriptCompiler::Source script_source(args[1]->ToString()); + ScriptCompiler::Source script_source(args[1]->ToString(isolate)); Handle script = ScriptCompiler::CompileUnbound( isolate, &script_source); if (script.IsEmpty()) return; @@ -526,7 +526,7 @@ void Shell::Write(const v8::FunctionCallbackInfo& args) { // Explicitly catch potential exceptions in toString(). v8::TryCatch try_catch; - Handle str_obj = args[i]->ToString(); + Handle str_obj = args[i]->ToString(args.GetIsolate()); if (try_catch.HasCaught()) { try_catch.ReThrow(); return; diff --git a/src/extensions/statistics-extension.cc b/src/extensions/statistics-extension.cc index 6f63245..bb5ee33 100644 --- a/src/extensions/statistics-extension.cc +++ b/src/extensions/statistics-extension.cc @@ -53,7 +53,8 @@ void StatisticsExtension::GetCounters( Heap* heap = isolate->heap(); if (args.Length() > 0) { // GC if first argument evaluates to true. - if (args[0]->IsBoolean() && args[0]->ToBoolean()->Value()) { + if (args[0]->IsBoolean() && + args[0]->ToBoolean(args.GetIsolate())->Value()) { heap->CollectAllGarbage(Heap::kNoGCFlags, "counters extension"); } }