From 696184a0477054897aec76946f3715682451ac5c Mon Sep 17 00:00:00 2001 From: jochen Date: Wed, 3 Jun 2015 03:27:46 -0700 Subject: [PATCH] Remove usage of to-be-deprecated APIs from v8 core Also turn on the macro to disable to-be-deprecated APIs for core BUG=v8:4134 R=vogelheim@chromium.org LOG=n Review URL: https://codereview.chromium.org/1162363005 Cr-Commit-Position: refs/heads/master@{#28783} --- include/v8.h | 26 +++++-- src/accessors.cc | 27 ++++++- src/api.cc | 73 +++++++++++++------ .../externalize-string-extension.cc | 42 +++++++---- src/extensions/gc-extension.cc | 7 +- src/extensions/statistics-extension.cc | 23 ++++-- src/full-codegen.cc | 10 ++- src/objects.cc | 4 +- src/runtime/runtime-test.cc | 11 ++- tools/gyp/v8.gyp | 4 + 10 files changed, 159 insertions(+), 68 deletions(-) diff --git a/include/v8.h b/include/v8.h index 3bd3dfbbd8..ab17d12b1c 100644 --- a/include/v8.h +++ b/include/v8.h @@ -7710,41 +7710,51 @@ template Value* Value::Cast(T* value) { Local Value::ToBoolean() const { - return ToBoolean(Isolate::GetCurrent()); + return ToBoolean(Isolate::GetCurrent()->GetCurrentContext()) + .FromMaybe(Local()); } Local Value::ToNumber() const { - return ToNumber(Isolate::GetCurrent()); + return ToNumber(Isolate::GetCurrent()->GetCurrentContext()) + .FromMaybe(Local()); } Local Value::ToString() const { - return ToString(Isolate::GetCurrent()); + return ToString(Isolate::GetCurrent()->GetCurrentContext()) + .FromMaybe(Local()); } Local Value::ToDetailString() const { - return ToDetailString(Isolate::GetCurrent()); + return ToDetailString(Isolate::GetCurrent()->GetCurrentContext()) + .FromMaybe(Local()); } Local Value::ToObject() const { - return ToObject(Isolate::GetCurrent()); + return ToObject(Isolate::GetCurrent()->GetCurrentContext()) + .FromMaybe(Local()); } Local Value::ToInteger() const { - return ToInteger(Isolate::GetCurrent()); + return ToInteger(Isolate::GetCurrent()->GetCurrentContext()) + .FromMaybe(Local()); } Local Value::ToUint32() const { - return ToUint32(Isolate::GetCurrent()); + return ToUint32(Isolate::GetCurrent()->GetCurrentContext()) + .FromMaybe(Local()); } -Local Value::ToInt32() const { return ToInt32(Isolate::GetCurrent()); } +Local Value::ToInt32() const { + return ToInt32(Isolate::GetCurrent()->GetCurrentContext()) + .FromMaybe(Local()); +} Boolean* Boolean::Cast(v8::Value* value) { diff --git a/src/accessors.cc b/src/accessors.cc index 4527001fc1..711d6dc11f 100644 --- a/src/accessors.cc +++ b/src/accessors.cc @@ -1402,9 +1402,19 @@ static void ModuleGetExport( JSModule* instance = JSModule::cast(*v8::Utils::OpenHandle(*info.Holder())); Context* context = Context::cast(instance->context()); DCHECK(context->IsModuleContext()); - int slot = info.Data()->Int32Value(); - Object* value = context->get(slot); Isolate* isolate = instance->GetIsolate(); + int slot = info.Data() + ->Int32Value(info.GetIsolate()->GetCurrentContext()) + .FromMaybe(-1); + if (slot < 0 || slot >= context->length()) { + Handle name = v8::Utils::OpenHandle(*property); + + Handle exception = isolate->factory()->NewReferenceError( + MessageTemplate::kNotDefined, name); + isolate->ScheduleThrow(*exception); + return; + } + Object* value = context->get(slot); if (value->IsTheHole()) { Handle name = v8::Utils::OpenHandle(*property); @@ -1424,9 +1434,18 @@ static void ModuleSetExport( JSModule* instance = JSModule::cast(*v8::Utils::OpenHandle(*info.Holder())); Context* context = Context::cast(instance->context()); DCHECK(context->IsModuleContext()); - int slot = info.Data()->Int32Value(); + Isolate* isolate = instance->GetIsolate(); + int slot = info.Data() + ->Int32Value(info.GetIsolate()->GetCurrentContext()) + .FromMaybe(-1); + if (slot < 0 || slot >= context->length()) { + Handle name = v8::Utils::OpenHandle(*property); + Handle exception = isolate->factory()->NewReferenceError( + MessageTemplate::kNotDefined, name); + isolate->ScheduleThrow(*exception); + return; + } Object* old_value = context->get(slot); - Isolate* isolate = context->GetIsolate(); if (old_value->IsTheHole()) { Handle name = v8::Utils::OpenHandle(*property); Handle exception = isolate->factory()->NewReferenceError( diff --git a/src/api.cc b/src/api.cc index 5140cd5060..6f9a745ab4 100644 --- a/src/api.cc +++ b/src/api.cc @@ -309,24 +309,32 @@ void V8::SetSnapshotDataBlob(StartupData* snapshot_blob) { } -bool RunExtraCode(Isolate* isolate, const char* utf8_source) { +bool RunExtraCode(Isolate* isolate, Local context, + const char* utf8_source) { // Run custom script if provided. base::ElapsedTimer timer; timer.Start(); TryCatch try_catch(isolate); - Local source_string = String::NewFromUtf8(isolate, utf8_source); - if (try_catch.HasCaught()) return false; - ScriptOrigin origin(String::NewFromUtf8(isolate, "")); + Local source_string; + if (!String::NewFromUtf8(isolate, utf8_source, NewStringType::kNormal) + .ToLocal(&source_string)) { + return false; + } + Local resource_name = + String::NewFromUtf8(isolate, "", NewStringType::kNormal) + .ToLocalChecked(); + ScriptOrigin origin(resource_name); ScriptCompiler::Source source(source_string, origin); - Local