[api] Use shorter 8::Local::As<*> casts in more places

Bug: v8:11195
Change-Id: I19211af9e440940f85351fb38920eb620c222213
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2555010
Reviewed-by: Ross McIlroy <rmcilroy@chromium.org>
Reviewed-by: Victor Gomes <victorgomes@chromium.org>
Commit-Queue: Camillo Bruni <cbruni@chromium.org>
Cr-Commit-Position: refs/heads/master@{#71465}
This commit is contained in:
Camillo Bruni 2020-11-27 17:06:57 +01:00 committed by Commit Bot
parent 29ab5697f4
commit 24222a9fef
21 changed files with 150 additions and 162 deletions

View File

@ -219,7 +219,7 @@ bool JsHttpRequestProcessor::Initialize(map<string, string>* opts,
}
// It is a function; cast it to a Function
Local<Function> process_fun = Local<Function>::Cast(process_val);
Local<Function> process_fun = process_val.As<Function>();
// Store the function in a Global handle, since we also want
// that to remain after this call returns
@ -375,7 +375,7 @@ Local<Object> JsHttpRequestProcessor::WrapMap(map<string, string>* obj) {
// Utility function that extracts the C++ map pointer from a wrapper
// object.
map<string, string>* JsHttpRequestProcessor::UnwrapMap(Local<Object> obj) {
Local<External> field = Local<External>::Cast(obj->GetInternalField(0));
Local<External> field = obj->GetInternalField(0).As<External>();
void* ptr = field->Value();
return static_cast<map<string, string>*>(ptr);
}
@ -397,7 +397,7 @@ void JsHttpRequestProcessor::MapGet(Local<Name> name,
map<string, string>* obj = UnwrapMap(info.Holder());
// Convert the JavaScript string to a std::string.
string key = ObjectToString(info.GetIsolate(), Local<String>::Cast(name));
string key = ObjectToString(info.GetIsolate(), name.As<String>());
// Look up the value if it exists using the standard STL ideom.
map<string, string>::iterator iter = obj->find(key);
@ -422,7 +422,7 @@ void JsHttpRequestProcessor::MapSet(Local<Name> name, Local<Value> value_obj,
map<string, string>* obj = UnwrapMap(info.Holder());
// Convert the key and value to std::strings.
string key = ObjectToString(info.GetIsolate(), Local<String>::Cast(name));
string key = ObjectToString(info.GetIsolate(), name.As<String>());
string value = ObjectToString(info.GetIsolate(), value_obj);
// Update the map.
@ -491,7 +491,7 @@ Local<Object> JsHttpRequestProcessor::WrapRequest(HttpRequest* request) {
* wrapper object.
*/
HttpRequest* JsHttpRequestProcessor::UnwrapRequest(Local<Object> obj) {
Local<External> field = Local<External>::Cast(obj->GetInternalField(0));
Local<External> field = obj->GetInternalField(0).As<External>();
void* ptr = field->Value();
return static_cast<HttpRequest*>(ptr);
}

View File

@ -380,7 +380,7 @@ void ReportException(v8::Isolate* isolate, v8::TryCatch* try_catch) {
v8::Local<v8::Value> stack_trace_string;
if (try_catch->StackTrace(context).ToLocal(&stack_trace_string) &&
stack_trace_string->IsString() &&
v8::Local<v8::String>::Cast(stack_trace_string)->Length() > 0) {
stack_trace_string.As<v8::String>()->Length() > 0) {
v8::String::Utf8Value stack_trace(isolate, stack_trace_string);
const char* stack_trace_string = ToCString(stack_trace);
fprintf(stderr, "%s\n", stack_trace_string);

View File

@ -52,7 +52,7 @@ static AsyncHooksWrap* UnwrapHook(
return nullptr;
}
Local<External> wrap = Local<External>::Cast(hook->GetInternalField(0));
Local<External> wrap = hook->GetInternalField(0).As<External>();
void* ptr = wrap->Value();
return static_cast<AsyncHooksWrap*>(ptr);
}

View File

@ -423,7 +423,7 @@ void Shell::System(const v8::FunctionCallbackInfo<v8::Value>& args) {
args.GetIsolate(), "system: Argument 2 must be an array"));
return;
}
command_args = Local<Array>::Cast(args[1]);
command_args = args[1].As<Array>();
} else {
command_args = Array::New(args.GetIsolate(), 0);
}

View File

@ -397,7 +397,7 @@ class TraceConfigParser {
Local<String> source =
String::NewFromUtf8(isolate, json_str).ToLocalChecked();
Local<Value> result = JSON::Parse(context, source).ToLocalChecked();
Local<v8::Object> trace_config_object = Local<v8::Object>::Cast(result);
Local<v8::Object> trace_config_object = result.As<v8::Object>();
UpdateIncludedCategoriesList(isolate, context, trace_config_object,
trace_config);
@ -410,7 +410,7 @@ class TraceConfigParser {
Local<Value> value =
GetValue(isolate, context, object, kIncludedCategoriesParam);
if (value->IsArray()) {
Local<Array> v8_array = Local<Array>::Cast(value);
Local<Array> v8_array = value.As<Array>();
for (int i = 0, length = v8_array->Length(); i < length; ++i) {
Local<Value> v = v8_array->Get(context, i)
.ToLocalChecked()
@ -1029,8 +1029,7 @@ MaybeLocal<Promise> Shell::HostImportModuleDynamically(
Local<Promise::Resolver> resolver;
if (maybe_resolver.ToLocal(&resolver)) {
DynamicImportData* data = new DynamicImportData(
isolate, Local<String>::Cast(referrer->GetResourceName()), specifier,
resolver);
isolate, referrer->GetResourceName().As<String>(), specifier, resolver);
isolate->EnqueueMicrotask(Shell::DoHostImportModuleDynamically, data);
return resolver->GetPromise();
}
@ -1108,7 +1107,7 @@ void Shell::DoHostImportModuleDynamically(void* import_data) {
Local<Value> module_namespace = root_module->GetModuleNamespace();
if (i::FLAG_harmony_top_level_await) {
Local<Promise> result_promise(Local<Promise>::Cast(result));
Local<Promise> result_promise(result.As<Promise>());
if (result_promise->State() == Promise::kRejected) {
resolver->Reject(realm, result_promise->Result()).ToChecked();
return;
@ -1176,7 +1175,7 @@ bool Shell::ExecuteModule(Isolate* isolate, const char* file_name) {
// Loop until module execution finishes
// TODO(cbruni): This is a bit wonky. "Real" engines would not be
// able to just busy loop waiting for execution to finish.
Local<Promise> result_promise(Local<Promise>::Cast(result));
Local<Promise> result_promise(result.As<Promise>());
while (result_promise->State() == Promise::kPending) {
isolate->PerformMicrotaskCheckpoint();
}
@ -1653,7 +1652,7 @@ void WriteToFile(FILE* file, const v8::FunctionCallbackInfo<v8::Value>& args) {
Local<String> str_obj;
if (arg->IsSymbol()) {
arg = Local<Symbol>::Cast(arg)->Description();
arg = arg.As<Symbol>()->Description();
}
if (!arg->ToString(args.GetIsolate()->GetCurrentContext())
.ToLocal(&str_obj)) {
@ -1776,7 +1775,7 @@ void Shell::SetTimeout(const v8::FunctionCallbackInfo<v8::Value>& args) {
Isolate* isolate = args.GetIsolate();
args.GetReturnValue().Set(v8::Number::New(isolate, 0));
if (args.Length() == 0 || !args[0]->IsFunction()) return;
Local<Function> callback = Local<Function>::Cast(args[0]);
Local<Function> callback = args[0].As<Function>();
Local<Context> context = isolate->GetCurrentContext();
PerIsolateData::Get(isolate)->SetTimeout(callback, context);
}
@ -1879,7 +1878,7 @@ void Shell::WorkerPostMessage(const v8::FunctionCallbackInfo<v8::Value>& args) {
Local<Value> message = args[0];
Local<Value> transfer =
args.Length() >= 2 ? args[1] : Local<Value>::Cast(Undefined(isolate));
args.Length() >= 2 ? args[1] : Undefined(isolate).As<Value>();
std::unique_ptr<SerializationData> data =
Shell::SerializeValue(isolate, message, transfer);
if (data) {
@ -2065,8 +2064,7 @@ void Shell::ReportException(Isolate* isolate, Local<v8::Message> message,
if (v8::TryCatch::StackTrace(context, exception_obj)
.ToLocal(&stack_trace_string) &&
stack_trace_string->IsString()) {
v8::String::Utf8Value stack_trace(isolate,
Local<String>::Cast(stack_trace_string));
v8::String::Utf8Value stack_trace(isolate, stack_trace_string.As<String>());
printf("%s\n", ToCString(stack_trace));
}
printf("\n");
@ -2858,11 +2856,10 @@ class InspectorFrontend final : public v8_inspector::V8Inspector::Channel {
if (callback->IsFunction()) {
v8::TryCatch try_catch(isolate_);
Local<Value> args[] = {message};
USE(Local<Function>::Cast(callback)->Call(context, Undefined(isolate_), 1,
args));
USE(callback.As<Function>()->Call(context, Undefined(isolate_), 1, args));
#ifdef DEBUG
if (try_catch.HasCaught()) {
Local<Object> exception = Local<Object>::Cast(try_catch.Exception());
Local<Object> exception = try_catch.Exception().As<Object>();
Local<String> key = v8::String::NewFromUtf8Literal(
isolate_, "message", NewStringType::kInternalized);
Local<String> expected = v8::String::NewFromUtf8Literal(
@ -2917,8 +2914,7 @@ class InspectorClient : public v8_inspector::V8InspectorClient {
is_paused = true;
while (is_paused) {
USE(Local<Function>::Cast(callback)->Call(context, Undefined(isolate_), 0,
{}));
USE(callback.As<Function>()->Call(context, Undefined(isolate_), 0, {}));
if (try_catch.HasCaught()) {
is_paused = false;
}
@ -3293,7 +3289,7 @@ void Worker::ProcessMessage(std::unique_ptr<SerializationData> data) {
if (!onmessage->IsFunction()) {
return;
}
Local<Function> onmessage_fun = Local<Function>::Cast(onmessage);
Local<Function> onmessage_fun = onmessage.As<Function>();
v8::TryCatch try_catch(isolate_);
try_catch.SetVerbose(true);
@ -3419,7 +3415,7 @@ void Worker::PostMessageOut(const v8::FunctionCallbackInfo<v8::Value>& args) {
Shell::SerializeValue(isolate, message, transfer);
if (data) {
DCHECK(args.Data()->IsExternal());
Local<External> this_value = Local<External>::Cast(args.Data());
Local<External> this_value = args.Data().As<External>();
Worker* worker = static_cast<Worker*>(this_value->Value());
worker->out_queue_.Enqueue(std::move(data));
worker->out_semaphore_.Signal();
@ -3954,7 +3950,7 @@ class Serializer : public ValueSerializer::Delegate {
private:
Maybe<bool> PrepareTransfer(Local<Context> context, Local<Value> transfer) {
if (transfer->IsArray()) {
Local<Array> transfer_array = Local<Array>::Cast(transfer);
Local<Array> transfer_array = transfer.As<Array>();
uint32_t length = transfer_array->Length();
for (uint32_t i = 0; i < length; ++i) {
Local<Value> element;
@ -3964,7 +3960,7 @@ class Serializer : public ValueSerializer::Delegate {
return Nothing<bool>();
}
Local<ArrayBuffer> array_buffer = Local<ArrayBuffer>::Cast(element);
Local<ArrayBuffer> array_buffer = element.As<ArrayBuffer>();
if (std::find(array_buffers_.begin(), array_buffers_.end(),
array_buffer) != array_buffers_.end()) {

View File

@ -82,7 +82,7 @@ class InjectedScript::ProtocolPromiseHandler {
}
v8::MaybeLocal<v8::Promise> originalPromise =
value->IsPromise() ? v8::Local<v8::Promise>::Cast(value)
value->IsPromise() ? value.As<v8::Promise>()
: v8::MaybeLocal<v8::Promise>();
V8InspectorImpl* inspector = session->inspector();
ProtocolPromiseHandler* handler = new ProtocolPromiseHandler(
@ -119,9 +119,8 @@ class InjectedScript::ProtocolPromiseHandler {
info.Data().As<v8::External>()->Value());
DCHECK(handler);
v8::Local<v8::Value> value =
info.Length() > 0
? info[0]
: v8::Local<v8::Value>::Cast(v8::Undefined(info.GetIsolate()));
info.Length() > 0 ? info[0]
: v8::Undefined(info.GetIsolate()).As<v8::Value>();
handler->thenCallback(value);
delete handler;
}
@ -131,9 +130,8 @@ class InjectedScript::ProtocolPromiseHandler {
info.Data().As<v8::External>()->Value());
DCHECK(handler);
v8::Local<v8::Value> value =
info.Length() > 0
? info[0]
: v8::Local<v8::Value>::Cast(v8::Undefined(info.GetIsolate()));
info.Length() > 0 ? info[0]
: v8::Undefined(info.GetIsolate()).As<v8::Value>();
handler->catchCallback(value);
delete handler;
}
@ -268,8 +266,8 @@ class InjectedScript::ProtocolPromiseHandler {
toProtocolString(isolate,
result->ToDetailString(isolate->GetCurrentContext())
.ToLocalChecked());
v8::Local<v8::StackTrace> stackTrace = v8::debug::GetDetailedStackTrace(
isolate, v8::Local<v8::Object>::Cast(result));
v8::Local<v8::StackTrace> stackTrace =
v8::debug::GetDetailedStackTrace(isolate, result.As<v8::Object>());
if (!stackTrace.IsEmpty()) {
stack = m_inspector->debugger()->createStackTrace(stackTrace);
}

View File

@ -70,8 +70,8 @@ InspectedContext::InspectedContext(V8InspectorImpl* inspector,
if (global->Get(info.context, toV8String(m_inspector->isolate(), "console"))
.ToLocal(&console) &&
console->IsObject()) {
m_inspector->console()->installMemoryGetter(
info.context, v8::Local<v8::Object>::Cast(console));
m_inspector->console()->installMemoryGetter(info.context,
console.As<v8::Object>());
}
}

View File

@ -90,34 +90,33 @@ class V8ValueStringBuilder {
if (value.IsEmpty()) return true;
if ((ignoreOptions & IgnoreNull) && value->IsNull()) return true;
if ((ignoreOptions & IgnoreUndefined) && value->IsUndefined()) return true;
if (value->IsString()) return append(v8::Local<v8::String>::Cast(value));
if (value->IsString()) return append(value.As<v8::String>());
if (value->IsStringObject())
return append(v8::Local<v8::StringObject>::Cast(value)->ValueOf());
if (value->IsBigInt()) return append(v8::Local<v8::BigInt>::Cast(value));
return append(value.As<v8::StringObject>()->ValueOf());
if (value->IsBigInt()) return append(value.As<v8::BigInt>());
if (value->IsBigIntObject())
return append(v8::Local<v8::BigIntObject>::Cast(value)->ValueOf());
if (value->IsSymbol()) return append(v8::Local<v8::Symbol>::Cast(value));
return append(value.As<v8::BigIntObject>()->ValueOf());
if (value->IsSymbol()) return append(value.As<v8::Symbol>());
if (value->IsSymbolObject())
return append(v8::Local<v8::SymbolObject>::Cast(value)->ValueOf());
return append(value.As<v8::SymbolObject>()->ValueOf());
if (value->IsNumberObject()) {
m_builder.append(String16::fromDouble(
v8::Local<v8::NumberObject>::Cast(value)->ValueOf(), 6));
m_builder.append(
String16::fromDouble(value.As<v8::NumberObject>()->ValueOf(), 6));
return true;
}
if (value->IsBooleanObject()) {
m_builder.append(v8::Local<v8::BooleanObject>::Cast(value)->ValueOf()
? "true"
m_builder.append(value.As<v8::BooleanObject>()->ValueOf() ? "true"
: "false");
return true;
}
if (value->IsArray()) return append(v8::Local<v8::Array>::Cast(value));
if (value->IsArray()) return append(value.As<v8::Array>());
if (value->IsProxy()) {
m_builder.append("[object Proxy]");
return true;
}
if (value->IsObject() && !value->IsDate() && !value->IsFunction() &&
!value->IsNativeError() && !value->IsRegExp()) {
v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(value);
v8::Local<v8::Object> object = value.As<v8::Object>();
v8::Local<v8::String> stringValue;
if (object->ObjectProtoToString(m_context).ToLocal(&stringValue))
return append(stringValue);
@ -267,7 +266,7 @@ V8ConsoleMessage::wrapArguments(V8InspectorSessionImpl* session,
if (m_arguments.size() > 1) {
v8::Local<v8::Value> secondArgument = m_arguments[1]->Get(isolate);
if (secondArgument->IsArray()) {
columns = v8::Local<v8::Array>::Cast(secondArgument);
columns = secondArgument.As<v8::Array>();
} else if (secondArgument->IsString()) {
v8::TryCatch tryCatch(isolate);
v8::Local<v8::Array> array = v8::Array::New(isolate);
@ -277,8 +276,7 @@ V8ConsoleMessage::wrapArguments(V8InspectorSessionImpl* session,
}
}
std::unique_ptr<protocol::Runtime::RemoteObject> wrapped =
session->wrapTable(context, v8::Local<v8::Object>::Cast(value),
columns);
session->wrapTable(context, value.As<v8::Object>(), columns);
inspectedContext = inspector->getContext(contextGroupId, contextId);
if (!inspectedContext) return nullptr;
if (wrapped) {

View File

@ -545,7 +545,7 @@ void V8Console::monitorFunctionCallback(
v8::Local<v8::Function> function;
if (!helper.firstArgAsFunction().ToLocal(&function)) return;
v8::Local<v8::Value> name = function->GetName();
if (!name->IsString() || !v8::Local<v8::String>::Cast(name)->Length())
if (!name->IsString() || !name.As<v8::String>()->Length())
name = function->GetInferredName();
String16 functionName =
toProtocolStringWithTypeCheck(info.GetIsolate(), name);
@ -844,7 +844,7 @@ V8Console::CommandLineAPIScope::CommandLineAPIScope(
if (!m_installedMethods->Add(context, name).ToLocal(&m_installedMethods))
continue;
if (!m_global
->SetAccessor(context, v8::Local<v8::Name>::Cast(name),
->SetAccessor(context, name.As<v8::Name>(),
CommandLineAPIScope::accessorGetterCallback,
CommandLineAPIScope::accessorSetterCallback,
m_thisReference, v8::DEFAULT, v8::DontEnum,
@ -869,9 +869,8 @@ V8Console::CommandLineAPIScope::~CommandLineAPIScope() {
if (!names->Get(m_context, i).ToLocal(&name) || !name->IsName()) continue;
if (name->IsString()) {
v8::Local<v8::Value> descriptor;
bool success = m_global
->GetOwnPropertyDescriptor(
m_context, v8::Local<v8::String>::Cast(name))
bool success =
m_global->GetOwnPropertyDescriptor(m_context, name.As<v8::String>())
.ToLocal(&descriptor);
USE(success);
}

View File

@ -657,7 +657,7 @@ v8::MaybeLocal<v8::Value> V8Debugger::getTargetScopes(
switch (kind) {
case FUNCTION:
iterator = v8::debug::ScopeIterator::CreateForFunction(
m_isolate, v8::Local<v8::Function>::Cast(value));
m_isolate, value.As<v8::Function>());
break;
case GENERATOR:
v8::Local<v8::debug::GeneratorObject> generatorObject =
@ -665,7 +665,7 @@ v8::MaybeLocal<v8::Value> V8Debugger::getTargetScopes(
if (!generatorObject->IsSuspended()) return v8::MaybeLocal<v8::Value>();
iterator = v8::debug::ScopeIterator::CreateForGeneratorObject(
m_isolate, v8::Local<v8::Object>::Cast(value));
m_isolate, value.As<v8::Object>());
break;
}
if (!iterator) return v8::MaybeLocal<v8::Value>();

View File

@ -615,7 +615,7 @@ Response V8RuntimeAgentImpl::queryObjects(
return Response::ServerError("Prototype should be instance of Object");
}
v8::Local<v8::Array> resultArray = m_inspector->debugger()->queryObjects(
scope.context(), v8::Local<v8::Object>::Cast(scope.object()));
scope.context(), scope.object().As<v8::Object>());
return scope.injectedScript()->wrapObject(
resultArray, objectGroup.fromMaybe(scope.objectGroupName()),
WrapMode::kNoPreview, objects);
@ -735,10 +735,8 @@ void V8RuntimeAgentImpl::bindingCallback(
int contextId = InspectedContext::contextId(isolate->GetCurrentContext());
int contextGroupId = inspector->contextGroupId(contextId);
String16 name =
toProtocolString(isolate, v8::Local<v8::String>::Cast(info.Data()));
String16 payload =
toProtocolString(isolate, v8::Local<v8::String>::Cast(info[0]));
String16 name = toProtocolString(isolate, info.Data().As<v8::String>());
String16 payload = toProtocolString(isolate, info[0].As<v8::String>());
inspector->forEachSession(
contextGroupId,

View File

@ -123,7 +123,7 @@ Response toProtocolValue(v8::Local<v8::Context> context,
if (value->IsObject()) {
std::unique_ptr<protocol::DictionaryValue> jsonObject =
protocol::DictionaryValue::create();
v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(value);
v8::Local<v8::Object> object = value.As<v8::Object>();
v8::Local<v8::Array> propertyNames;
if (!object->GetPropertyNames(context).ToLocal(&propertyNames))
return Response::InternalError();
@ -134,8 +134,8 @@ Response toProtocolValue(v8::Local<v8::Context> context,
return Response::InternalError();
// FIXME(yurys): v8::Object should support GetOwnPropertyNames
if (name->IsString()) {
v8::Maybe<bool> hasRealNamedProperty = object->HasRealNamedProperty(
context, v8::Local<v8::String>::Cast(name));
v8::Maybe<bool> hasRealNamedProperty =
object->HasRealNamedProperty(context, name.As<v8::String>());
if (hasRealNamedProperty.IsNothing() ||
!hasRealNamedProperty.FromJust())
continue;
@ -883,7 +883,7 @@ bool isArrayLike(v8::Local<v8::Context> context, v8::Local<v8::Value> value,
!lengthValue->IsUint32()) {
return false;
}
*length = v8::Local<v8::Uint32>::Cast(lengthValue)->Value();
*length = lengthValue.As<v8::Uint32>()->Value();
return true;
}
@ -1904,7 +1904,7 @@ std::unique_ptr<ValueMirror> ValueMirror::create(v8::Local<v8::Context> context,
descriptionForCollection(isolate, view, view->ByteLength()));
}
V8InternalValueType internalType =
v8InternalValueTypeFrom(context, v8::Local<v8::Object>::Cast(value));
v8InternalValueTypeFrom(context, value.As<v8::Object>());
if (value->IsArray() && internalType == V8InternalValueType::kScopeList) {
return std::make_unique<ObjectMirror>(
value, "internal#scopeList",

View File

@ -63,11 +63,10 @@ bool IsWasmCompileAllowed(v8::Isolate* isolate, v8::Local<v8::Value> value,
DCHECK_GT(GetPerIsolateWasmControls()->count(isolate), 0);
const WasmCompileControls& ctrls = GetPerIsolateWasmControls()->at(isolate);
return (is_async && ctrls.AllowAnySizeForAsync) ||
(value->IsArrayBuffer() &&
v8::Local<v8::ArrayBuffer>::Cast(value)->ByteLength() <=
(value->IsArrayBuffer() && value.As<v8::ArrayBuffer>()->ByteLength() <=
ctrls.MaxWasmBufferSize) ||
(value->IsArrayBufferView() &&
v8::Local<v8::ArrayBufferView>::Cast(value)->ByteLength() <=
value.As<v8::ArrayBufferView>()->ByteLength() <=
ctrls.MaxWasmBufferSize);
}

View File

@ -194,8 +194,7 @@ void VTUNEJITInterface::event_handler(const v8::JitCodeEvent* event) {
if (*script != NULL) {
// Get the source file name and set it to jmethod.source_file_name
if ((*script->GetScriptName())->IsString()) {
Local<String> script_name =
Local<String>::Cast(script->GetScriptName());
Local<String> script_name = script->GetScriptName().As<String>();
temp_file_name.reset(
new char[script_name->Utf8Length(event->isolate) + 1]);
script_name->WriteUtf8(event->isolate, temp_file_name.get());

View File

@ -166,10 +166,11 @@ Handle<BytecodeArray> OptimizedBytecodeSourcePositionTester::MakeBytecode(
SetOptimizationFlags(optimization_bitmap);
CompileRun(script.c_str());
Local<Function> api_function = Local<Function>::Cast(
Local<Function> api_function =
CcTest::global()
->Get(CcTest::isolate()->GetCurrentContext(), v8_str("test_function"))
.ToLocalChecked());
.ToLocalChecked()
.As<Function>();
Handle<JSFunction> function =
Handle<JSFunction>::cast(v8::Utils::OpenHandle(*api_function));
return handle(function->shared().GetBytecodeArray(), isolate_);

View File

@ -97,8 +97,10 @@ static const char* sampler_test_source = "function start(count) {\n"
static v8::Local<v8::Function> GetFunction(v8::Local<v8::Context> env,
const char* name) {
return v8::Local<v8::Function>::Cast(
env->Global()->Get(env, v8_str(name)).ToLocalChecked());
return env->Global()
->Get(env, v8_str(name))
.ToLocalChecked()
.As<v8::Function>();
}

View File

@ -27,8 +27,6 @@
#include <stdlib.h>
#include "src/init/v8.h"
#include "src/api/api-inl.h"
#include "src/execution/frames-inl.h"
#include "src/strings/string-stream.h"
@ -149,8 +147,7 @@ THREADED_TEST(PropertyHandler) {
static void GetIntValue(Local<String> property,
const v8::PropertyCallbackInfo<v8::Value>& info) {
ApiTestFuzzer::Fuzz();
int* value =
static_cast<int*>(v8::Local<v8::External>::Cast(info.Data())->Value());
int* value = static_cast<int*>(info.Data().As<v8::External>()->Value());
info.GetReturnValue().Set(v8_num(*value));
}
@ -158,8 +155,7 @@ static void GetIntValue(Local<String> property,
static void SetIntValue(Local<String> property,
Local<Value> value,
const v8::PropertyCallbackInfo<void>& info) {
int* field =
static_cast<int*>(v8::Local<v8::External>::Cast(info.Data())->Value());
int* field = static_cast<int*>(info.Data().As<v8::External>()->Value());
*field = value->Int32Value(info.GetIsolate()->GetCurrentContext()).FromJust();
}

View File

@ -2,9 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "test/cctest/test-api.h"
#include "src/api/api-inl.h"
#include "test/cctest/test-api.h"
using ::v8::Array;
using ::v8::Context;
@ -30,8 +29,7 @@ void CheckIsTypedArrayVarDetached(const char* name) {
"%s.byteLength == 0 && %s.byteOffset == 0 && %s.length == 0",
name, name, name);
CHECK(CompileRun(source.begin())->IsTrue());
v8::Local<v8::TypedArray> ta =
v8::Local<v8::TypedArray>::Cast(CompileRun(name));
v8::Local<v8::TypedArray> ta = CompileRun(name).As<v8::TypedArray>();
CheckIsDetached(ta);
}
@ -122,7 +120,7 @@ THREADED_TEST(ArrayBuffer_JSInternalToExternal) {
"var u8_a = new Uint8Array(ab1);"
"u8_a[0] = 0xAA;"
"u8_a[1] = 0xFF; u8_a.buffer");
Local<v8::ArrayBuffer> ab1 = Local<v8::ArrayBuffer>::Cast(result);
Local<v8::ArrayBuffer> ab1 = result.As<v8::ArrayBuffer>();
CheckInternalFieldsAreZero(ab1);
CHECK_EQ(2, ab1->ByteLength());
std::shared_ptr<v8::BackingStore> backing_store = Externalize(ab1);
@ -272,10 +270,8 @@ THREADED_TEST(ArrayBuffer_DetachingScript) {
"var f64a = new Float64Array(ab, 8, 127);"
"var dv = new DataView(ab, 1, 1023);");
v8::Local<v8::ArrayBuffer> ab =
Local<v8::ArrayBuffer>::Cast(CompileRun("ab"));
v8::Local<v8::DataView> dv = v8::Local<v8::DataView>::Cast(CompileRun("dv"));
v8::Local<v8::ArrayBuffer> ab = CompileRun("ab").As<v8::ArrayBuffer>();
v8::Local<v8::DataView> dv = CompileRun("dv").As<v8::DataView>();
Externalize(ab);
ab->Detach();
@ -424,7 +420,7 @@ THREADED_TEST(SharedArrayBuffer_JSInternalToExternal) {
"var u8_a = new Uint8Array(ab1);"
"u8_a[0] = 0xAA;"
"u8_a[1] = 0xFF; u8_a.buffer");
Local<v8::SharedArrayBuffer> ab1 = Local<v8::SharedArrayBuffer>::Cast(result);
Local<v8::SharedArrayBuffer> ab1 = result.As<v8::SharedArrayBuffer>();
CheckInternalFieldsAreZero(ab1);
CHECK_EQ(2, ab1->ByteLength());
CHECK(!ab1->IsExternal());

View File

@ -75,7 +75,7 @@ void EmptyInterceptorEnumerator(
void SimpleAccessorGetter(Local<String> name,
const v8::PropertyCallbackInfo<v8::Value>& info) {
Local<Object> self = Local<Object>::Cast(info.This());
Local<Object> self = info.This().As<Object>();
info.GetReturnValue().Set(
self->Get(info.GetIsolate()->GetCurrentContext(),
String::Concat(info.GetIsolate(), v8_str("accessor_"), name))
@ -84,7 +84,7 @@ void SimpleAccessorGetter(Local<String> name,
void SimpleAccessorSetter(Local<String> name, Local<Value> value,
const v8::PropertyCallbackInfo<void>& info) {
Local<Object> self = Local<Object>::Cast(info.This());
Local<Object> self = info.This().As<Object>();
self->Set(info.GetIsolate()->GetCurrentContext(),
String::Concat(info.GetIsolate(), v8_str("accessor_"), name), value)
.FromJust();
@ -94,23 +94,23 @@ void SimpleAccessorSetter(Local<String> name, Local<Value> value,
void SymbolAccessorGetter(Local<Name> name,
const v8::PropertyCallbackInfo<v8::Value>& info) {
CHECK(name->IsSymbol());
Local<Symbol> sym = Local<Symbol>::Cast(name);
Local<Symbol> sym = name.As<Symbol>();
if (sym->Description()->IsUndefined()) return;
SimpleAccessorGetter(Local<String>::Cast(sym->Description()), info);
SimpleAccessorGetter(sym->Description().As<String>(), info);
}
void SymbolAccessorSetter(Local<Name> name, Local<Value> value,
const v8::PropertyCallbackInfo<void>& info) {
CHECK(name->IsSymbol());
Local<Symbol> sym = Local<Symbol>::Cast(name);
Local<Symbol> sym = name.As<Symbol>();
if (sym->Description()->IsUndefined()) return;
SimpleAccessorSetter(Local<String>::Cast(sym->Description()), value, info);
SimpleAccessorSetter(sym->Description().As<String>(), value, info);
}
void InterceptorGetter(Local<Name> generic_name,
const v8::PropertyCallbackInfo<v8::Value>& info) {
if (generic_name->IsSymbol()) return;
Local<String> name = Local<String>::Cast(generic_name);
Local<String> name = generic_name.As<String>();
String::Utf8Value utf8(info.GetIsolate(), name);
char* name_str = *utf8;
char prefix[] = "interceptor_";
@ -118,7 +118,7 @@ void InterceptorGetter(Local<Name> generic_name,
for (i = 0; name_str[i] && prefix[i]; ++i) {
if (name_str[i] != prefix[i]) return;
}
Local<Object> self = Local<Object>::Cast(info.This());
Local<Object> self = info.This().As<Object>();
info.GetReturnValue().Set(
self->GetPrivate(
info.GetIsolate()->GetCurrentContext(),
@ -129,7 +129,7 @@ void InterceptorGetter(Local<Name> generic_name,
void InterceptorSetter(Local<Name> generic_name, Local<Value> value,
const v8::PropertyCallbackInfo<v8::Value>& info) {
if (generic_name->IsSymbol()) return;
Local<String> name = Local<String>::Cast(generic_name);
Local<String> name = generic_name.As<String>();
// Intercept accesses that set certain integer values, for which the name does
// not start with 'accessor_'.
String::Utf8Value utf8(info.GetIsolate(), name);
@ -143,7 +143,7 @@ void InterceptorSetter(Local<Name> generic_name, Local<Value> value,
Local<Context> context = info.GetIsolate()->GetCurrentContext();
if (value->IsInt32() && value->Int32Value(context).FromJust() < 10000) {
Local<Object> self = Local<Object>::Cast(info.This());
Local<Object> self = info.This().As<Object>();
Local<v8::Private> symbol = v8::Private::ForApi(info.GetIsolate(), name);
self->SetPrivate(context, symbol, value).FromJust();
info.GetReturnValue().Set(value);
@ -154,19 +154,18 @@ void GenericInterceptorGetter(Local<Name> generic_name,
const v8::PropertyCallbackInfo<v8::Value>& info) {
Local<String> str;
if (generic_name->IsSymbol()) {
Local<Value> name = Local<Symbol>::Cast(generic_name)->Description();
Local<Value> name = generic_name.As<Symbol>()->Description();
if (name->IsUndefined()) return;
str = String::Concat(info.GetIsolate(), v8_str("_sym_"),
Local<String>::Cast(name));
str = String::Concat(info.GetIsolate(), v8_str("_sym_"), name.As<String>());
} else {
Local<String> name = Local<String>::Cast(generic_name);
Local<String> name = generic_name.As<String>();
String::Utf8Value utf8(info.GetIsolate(), name);
char* name_str = *utf8;
if (*name_str == '_') return;
str = String::Concat(info.GetIsolate(), v8_str("_str_"), name);
}
Local<Object> self = Local<Object>::Cast(info.This());
Local<Object> self = info.This().As<Object>();
info.GetReturnValue().Set(
self->Get(info.GetIsolate()->GetCurrentContext(), str).ToLocalChecked());
}
@ -175,19 +174,18 @@ void GenericInterceptorSetter(Local<Name> generic_name, Local<Value> value,
const v8::PropertyCallbackInfo<v8::Value>& info) {
Local<String> str;
if (generic_name->IsSymbol()) {
Local<Value> name = Local<Symbol>::Cast(generic_name)->Description();
Local<Value> name = generic_name.As<Symbol>()->Description();
if (name->IsUndefined()) return;
str = String::Concat(info.GetIsolate(), v8_str("_sym_"),
Local<String>::Cast(name));
str = String::Concat(info.GetIsolate(), v8_str("_sym_"), name.As<String>());
} else {
Local<String> name = Local<String>::Cast(generic_name);
Local<String> name = generic_name.As<String>();
String::Utf8Value utf8(info.GetIsolate(), name);
char* name_str = *utf8;
if (*name_str == '_') return;
str = String::Concat(info.GetIsolate(), v8_str("_str_"), name);
}
Local<Object> self = Local<Object>::Cast(info.This());
Local<Object> self = info.This().As<Object>();
self->Set(info.GetIsolate()->GetCurrentContext(), str, value).FromJust();
info.GetReturnValue().Set(value);
}
@ -1101,7 +1099,8 @@ THREADED_TEST(InterceptorLoadICInvalidatedFieldViaGlobal) {
static void SetOnThis(Local<String> name, Local<Value> value,
const v8::PropertyCallbackInfo<void>& info) {
Local<Object>::Cast(info.This())
info.This()
.As<Object>()
->CreateDataProperty(info.GetIsolate()->GetCurrentContext(), name, value)
.FromJust();
}
@ -3017,7 +3016,7 @@ void UnboxedDoubleIndexedPropertyEnumerator(
Local<Value> result =
indexed_property_names_script->Run(info.GetIsolate()->GetCurrentContext())
.ToLocalChecked();
info.GetReturnValue().Set(Local<v8::Array>::Cast(result));
info.GetReturnValue().Set(result.As<v8::Array>());
}
@ -3062,9 +3061,10 @@ void SloppyArgsIndexedPropertyEnumerator(
"}"
"keys = f(0, 1, 2, 3);"
"keys;");
Local<Object> result = Local<Object>::Cast(
Local<Object> result =
indexed_property_names_script->Run(info.GetIsolate()->GetCurrentContext())
.ToLocalChecked());
.ToLocalChecked()
.As<Object>();
// Have to populate the handle manually, as it's not Cast-able.
i::Handle<i::JSReceiver> o =
v8::Utils::OpenHandle<Object, i::JSReceiver>(result);
@ -3633,8 +3633,8 @@ THREADED_TEST(Enumerators) {
->Set(context.local(), v8_str("k"),
obj->NewInstance(context.local()).ToLocalChecked())
.FromJust();
v8::Local<v8::Array> result =
v8::Local<v8::Array>::Cast(CompileRun("k[10] = 0;"
v8::Local<v8::Array> result = CompileRun(
"k[10] = 0;"
"k.a = 0;"
"k[5] = 0;"
"k.b = 0;"
@ -3650,7 +3650,8 @@ THREADED_TEST(Enumerators) {
"for (var prop in k) {"
" result.push(prop);"
"}"
"result"));
"result")
.As<v8::Array>();
// Check that we get all the property names returned including the
// ones from the enumerators in the right order: indexed properties
// in numerical order, indexed interceptor properties, named
@ -4731,7 +4732,7 @@ THREADED_TEST(GetOwnPropertyNamesWithInterceptor) {
v8::Local<v8::Value> result =
CompileRun("Object.getOwnPropertyNames(object)");
CHECK(result->IsArray());
v8::Local<v8::Array> result_array = v8::Local<v8::Array>::Cast(result);
v8::Local<v8::Array> result_array = result.As<v8::Array>();
CHECK_EQ(2u, result_array->Length());
CHECK(result_array->Get(context.local(), 0).ToLocalChecked()->IsString());
CHECK(result_array->Get(context.local(), 1).ToLocalChecked()->IsString());
@ -4746,7 +4747,7 @@ THREADED_TEST(GetOwnPropertyNamesWithInterceptor) {
result = CompileRun("var ret = []; for (var k in object) ret.push(k); ret");
CHECK(result->IsArray());
result_array = v8::Local<v8::Array>::Cast(result);
result_array = result.As<v8::Array>();
CHECK_EQ(2u, result_array->Length());
CHECK(result_array->Get(context.local(), 0).ToLocalChecked()->IsString());
CHECK(result_array->Get(context.local(), 1).ToLocalChecked()->IsString());
@ -4761,7 +4762,7 @@ THREADED_TEST(GetOwnPropertyNamesWithInterceptor) {
result = CompileRun("Object.getOwnPropertySymbols(object)");
CHECK(result->IsArray());
result_array = v8::Local<v8::Array>::Cast(result);
result_array = result.As<v8::Array>();
CHECK_EQ(1u, result_array->Length());
CHECK(result_array->Get(context.local(), 0)
.ToLocalChecked()

View File

@ -2276,6 +2276,7 @@ THREADED_TEST(TestDataTypeChecks) {
CHECK(!x->IsObjectTemplate());
CHECK(!x->IsFunctionTemplate());
v8::Local<v8::Value>::Cast(x);
x.As<v8::Value>();
}
v8::ScriptOrigin origin(v8_str(""), 0, 0, false, -1, Local<v8::Value>(),
@ -2290,6 +2291,7 @@ THREADED_TEST(TestDataTypeChecks) {
CHECK(!module->IsObjectTemplate());
CHECK(!module->IsFunctionTemplate());
v8::Local<v8::Module>::Cast(module);
module.As<v8::Module>();
v8::Local<v8::Data> p = v8::Private::New(isolate);
CHECK(!p->IsModule());
@ -2604,7 +2606,7 @@ THREADED_TEST(DescriptorInheritance2) {
void SimpleAccessorGetter(Local<String> name,
const v8::PropertyCallbackInfo<v8::Value>& info) {
Local<Object> self = Local<Object>::Cast(info.This());
Local<Object> self = info.This().As<Object>();
info.GetReturnValue().Set(
self->Get(info.GetIsolate()->GetCurrentContext(),
String::Concat(info.GetIsolate(), v8_str("accessor_"), name))
@ -2613,7 +2615,7 @@ void SimpleAccessorGetter(Local<String> name,
void SimpleAccessorSetter(Local<String> name, Local<Value> value,
const v8::PropertyCallbackInfo<void>& info) {
Local<Object> self = Local<Object>::Cast(info.This());
Local<Object> self = info.This().As<Object>();
CHECK(self->Set(info.GetIsolate()->GetCurrentContext(),
String::Concat(info.GetIsolate(), v8_str("accessor_"), name),
value)
@ -2623,7 +2625,7 @@ void SimpleAccessorSetter(Local<String> name, Local<Value> value,
void SymbolAccessorGetter(Local<Name> name,
const v8::PropertyCallbackInfo<v8::Value>& info) {
CHECK(name->IsSymbol());
Local<Symbol> sym = Local<Symbol>::Cast(name);
Local<Symbol> sym = name.As<Symbol>();
if (sym->Description()->IsUndefined()) return;
SimpleAccessorGetter(Local<String>::Cast(sym->Description()), info);
}
@ -2631,7 +2633,7 @@ void SymbolAccessorGetter(Local<Name> name,
void SymbolAccessorSetter(Local<Name> name, Local<Value> value,
const v8::PropertyCallbackInfo<void>& info) {
CHECK(name->IsSymbol());
Local<Symbol> sym = Local<Symbol>::Cast(name);
Local<Symbol> sym = name.As<Symbol>();
if (sym->Description()->IsUndefined()) return;
SimpleAccessorSetter(Local<String>::Cast(sym->Description()), value, info);
}
@ -2639,7 +2641,7 @@ void SymbolAccessorSetter(Local<Name> name, Local<Value> value,
void SymbolAccessorGetterReturnsDefault(
Local<Name> name, const v8::PropertyCallbackInfo<v8::Value>& info) {
CHECK(name->IsSymbol());
Local<Symbol> sym = Local<Symbol>::Cast(name);
Local<Symbol> sym = name.As<Symbol>();
if (sym->Description()->IsUndefined()) return;
info.GetReturnValue().Set(info.Data());
}
@ -8828,7 +8830,7 @@ static void YGetter(Local<String> name,
static void YSetter(Local<String> name,
Local<Value> value,
const v8::PropertyCallbackInfo<void>& info) {
Local<Object> this_obj = Local<Object>::Cast(info.This());
Local<Object> this_obj = info.This().As<Object>();
v8::Local<v8::Context> context = info.GetIsolate()->GetCurrentContext();
if (this_obj->Has(context, name).FromJust())
this_obj->Delete(context, name).FromJust();
@ -17588,7 +17590,8 @@ static void SetterWhichSetsYOnThisTo23(
const v8::PropertyCallbackInfo<void>& info) {
CHECK(v8::Utils::OpenHandle(*info.This())->IsJSObject());
CHECK(v8::Utils::OpenHandle(*info.Holder())->IsJSObject());
Local<Object>::Cast(info.This())
info.This()
.As<Object>()
->Set(info.GetIsolate()->GetCurrentContext(), v8_str("y"), v8_num(23))
.FromJust();
}
@ -17614,7 +17617,8 @@ void FooSetInterceptor(Local<Name> name, Local<Value> value,
.FromJust()) {
return;
}
Local<Object>::Cast(info.This())
info.This()
.As<Object>()
->Set(info.GetIsolate()->GetCurrentContext(), v8_str("y"), v8_num(23))
.FromJust();
info.GetReturnValue().Set(v8_num(23));
@ -17678,7 +17682,8 @@ static void NamedPropertySetterWhichSetsYOnThisTo23(
const v8::PropertyCallbackInfo<v8::Value>& info) {
if (name->Equals(info.GetIsolate()->GetCurrentContext(), v8_str("x"))
.FromJust()) {
Local<Object>::Cast(info.This())
info.This()
.As<Object>()
->Set(info.GetIsolate()->GetCurrentContext(), v8_str("y"), v8_num(23))
.FromJust();
}

View File

@ -330,7 +330,7 @@ TEST(ModuleEvaluation) {
MaybeLocal<Value> result = module->Evaluate(env.local());
CHECK_EQ(Module::kEvaluated, module->GetStatus());
if (i::FLAG_harmony_top_level_await) {
Local<Promise> promise = Local<Promise>::Cast(result.ToLocalChecked());
Local<Promise> promise = result.ToLocalChecked().As<Promise>();
CHECK_EQ(promise->State(), v8::Promise::kFulfilled);
CHECK(promise->Result()->IsUndefined());
} else {
@ -377,7 +377,7 @@ TEST(ModuleEvaluationError1) {
// With top level await, we do not throw and errored evaluation returns
// a rejected promise with the exception.
CHECK(!inner_try_catch.HasCaught());
Local<Promise> promise = Local<Promise>::Cast(result.ToLocalChecked());
Local<Promise> promise = result.ToLocalChecked().As<Promise>();
CHECK_EQ(promise->State(), v8::Promise::kRejected);
CHECK_EQ(promise->Result(), module->GetException());
} else {
@ -399,7 +399,7 @@ TEST(ModuleEvaluationError1) {
// With top level await, we do not throw and errored evaluation returns
// a rejected promise with the exception.
CHECK(!inner_try_catch.HasCaught());
Local<Promise> promise = Local<Promise>::Cast(result.ToLocalChecked());
Local<Promise> promise = result.ToLocalChecked().As<Promise>();
CHECK_EQ(promise->State(), v8::Promise::kRejected);
CHECK_EQ(promise->Result(), module->GetException());
} else {
@ -460,7 +460,7 @@ TEST(ModuleEvaluationError2) {
// With top level await, we do not throw and errored evaluation returns
// a rejected promise with the exception.
CHECK(!inner_try_catch.HasCaught());
Local<Promise> promise = Local<Promise>::Cast(result.ToLocalChecked());
Local<Promise> promise = result.ToLocalChecked().As<Promise>();
CHECK_EQ(promise->State(), v8::Promise::kRejected);
CHECK_EQ(promise->Result(), failure_module->GetException());
} else {
@ -496,7 +496,7 @@ TEST(ModuleEvaluationError2) {
// With top level await, we do not throw and errored evaluation returns
// a rejected promise with the exception.
CHECK(!inner_try_catch.HasCaught());
Local<Promise> promise = Local<Promise>::Cast(result.ToLocalChecked());
Local<Promise> promise = result.ToLocalChecked().As<Promise>();
CHECK_EQ(promise->State(), v8::Promise::kRejected);
CHECK_EQ(promise->Result(), failure_module->GetException());
} else {
@ -561,12 +561,12 @@ TEST(ModuleEvaluationCompletion1) {
CHECK_EQ(Module::kEvaluated, module->GetStatus());
if (i::FLAG_harmony_top_level_await) {
Local<Promise> promise = Local<Promise>::Cast(result_1);
Local<Promise> promise = result_1.As<Promise>();
CHECK_EQ(promise->State(), v8::Promise::kFulfilled);
CHECK(promise->Result()->IsUndefined());
// Second evaluation should return the same promise.
Local<Promise> promise_too = Local<Promise>::Cast(result_2);
Local<Promise> promise_too = result_2.As<Promise>();
CHECK_EQ(promise, promise_too);
CHECK_EQ(promise_too->State(), v8::Promise::kFulfilled);
CHECK(promise_too->Result()->IsUndefined());
@ -628,12 +628,12 @@ TEST(ModuleEvaluationCompletion2) {
Local<Value> result_2 = module->Evaluate(env.local()).ToLocalChecked();
CHECK_EQ(Module::kEvaluated, module->GetStatus());
if (i::FLAG_harmony_top_level_await) {
Local<Promise> promise = Local<Promise>::Cast(result_1);
Local<Promise> promise = result_1.As<Promise>();
CHECK_EQ(promise->State(), v8::Promise::kFulfilled);
CHECK(promise->Result()->IsUndefined());
// Second Evaluation should return the same promise.
Local<Promise> promise_too = Local<Promise>::Cast(result_2);
Local<Promise> promise_too = result_2.As<Promise>();
CHECK_EQ(promise, promise_too);
CHECK_EQ(promise_too->State(), v8::Promise::kFulfilled);
CHECK(promise_too->Result()->IsUndefined());