convert most remaining api functions needing context to maybes

BUG=

Review URL: https://codereview.chromium.org/993223003

Cr-Commit-Position: refs/heads/master@{#27126}
This commit is contained in:
dcarney 2015-03-11 02:32:57 -07:00 committed by Commit bot
parent 45e4a78911
commit 5234d9977d
3 changed files with 131 additions and 122 deletions

View File

@ -202,13 +202,22 @@ class V8_EXPORT Debug {
* }
* \endcode
*/
static Local<Value> Call(v8::Handle<v8::Function> fun,
Handle<Value> data = Handle<Value>());
static V8_DEPRECATE_SOON(
"Use maybe version",
Local<Value> Call(v8::Handle<v8::Function> fun,
Handle<Value> data = Handle<Value>()));
// TODO(dcarney): data arg should be a MaybeLocal
static MaybeLocal<Value> Call(Local<Context> context,
v8::Handle<v8::Function> fun,
Handle<Value> data = Handle<Value>());
/**
* Returns a mirror object for the given object.
*/
static Local<Value> GetMirror(v8::Handle<v8::Value> obj);
static V8_DEPRECATE_SOON("Use maybe version",
Local<Value> GetMirror(v8::Handle<v8::Value> obj));
static MaybeLocal<Value> GetMirror(Local<Context> context,
v8::Handle<v8::Value> obj);
/**
* Makes V8 process all pending debug messages.

View File

@ -2926,7 +2926,9 @@ class V8_EXPORT Array : public Object {
* Clones an element at index |index|. Returns an empty
* handle if cloning fails (for any reason).
*/
Local<Object> CloneElementAt(uint32_t index);
V8_DEPRECATE_SOON("Use maybe version",
Local<Object> CloneElementAt(uint32_t index));
MaybeLocal<Object> CloneElementAt(Local<Context> context, uint32_t index);
/**
* Creates a JavaScript array with the given length. If the length
@ -3682,7 +3684,11 @@ class V8_EXPORT RegExp : public Object {
* static_cast<RegExp::Flags>(kGlobal | kMultiline))
* is equivalent to evaluating "/foo/gm".
*/
static Local<RegExp> New(Handle<String> pattern, Flags flags);
static V8_DEPRECATE_SOON("Use maybe version",
Local<RegExp> New(Handle<String> pattern,
Flags flags));
static MaybeLocal<RegExp> New(Local<Context> context, Handle<String> pattern,
Flags flags);
/**
* Returns the value of the source property: a string representing
@ -4066,7 +4072,8 @@ class V8_EXPORT FunctionTemplate : public Template {
int length = 0);
/** Returns the unique function instance in the current execution context.*/
Local<Function> GetFunction();
V8_DEPRECATE_SOON("Use maybe version", Local<Function> GetFunction());
MaybeLocal<Function> GetFunction(Local<Context> context);
/**
* Set the call-handler callback for a FunctionTemplate. This
@ -4209,7 +4216,8 @@ class V8_EXPORT ObjectTemplate : public Template {
static V8_DEPRECATE_SOON("Use isolate version", Local<ObjectTemplate> New());
/** Creates a new instance of this template.*/
Local<Object> NewInstance();
V8_DEPRECATE_SOON("Use maybe version", Local<Object> NewInstance());
MaybeLocal<Object> NewInstance(Local<Context> context);
/**
* Sets an accessor on the object template.

View File

@ -59,13 +59,6 @@
namespace v8 {
#define ON_BAILOUT(isolate, location, code) \
if (IsExecutionTerminatingCheck(isolate)) { \
code; \
UNREACHABLE(); \
}
#define EXCEPTION_PREAMBLE(isolate) \
(isolate)->handle_scope_implementer()->IncrementCallDepth(); \
DCHECK(!(isolate)->external_caught_exception()); \
@ -5485,7 +5478,6 @@ Local<Context> v8::Context::New(
v8::Handle<Value> global_object) {
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(external_isolate);
LOG_API(isolate, "Context::New");
ON_BAILOUT(isolate, "v8::Context::New()", return Local<Context>());
i::HandleScope scope(isolate);
ExtensionConfiguration no_extensions;
if (extensions == NULL) extensions = &no_extensions;
@ -5569,44 +5561,45 @@ void Context::SetErrorMessageForCodeGenerationFromStrings(
}
Local<v8::Object> ObjectTemplate::NewInstance() {
i::Handle<i::ObjectTemplateInfo> info = Utils::OpenHandle(this);
i::Isolate* isolate = info->GetIsolate();
ON_BAILOUT(isolate, "v8::ObjectTemplate::NewInstance()",
return Local<v8::Object>());
LOG_API(isolate, "ObjectTemplate::NewInstance");
ENTER_V8(isolate);
EXCEPTION_PREAMBLE(isolate);
i::Handle<i::Object> obj;
MaybeLocal<v8::Object> ObjectTemplate::NewInstance(Local<Context> context) {
PREPARE_FOR_EXECUTION(context, "v8::ObjectTemplate::NewInstance()", Object);
auto self = Utils::OpenHandle(this);
Local<Object> result;
has_pending_exception =
!i::ApiNatives::InstantiateObject(info).ToHandle(&obj);
EXCEPTION_BAILOUT_CHECK(isolate, Local<v8::Object>());
return Utils::ToLocal(i::Handle<i::JSObject>::cast(obj));
!ToLocal<Object>(i::ApiNatives::InstantiateObject(self), &result);
RETURN_ON_FAILED_EXECUTION(Object);
RETURN_ESCAPED(result);
}
Local<v8::Object> ObjectTemplate::NewInstance() {
auto context = ContextFromHeapObject(Utils::OpenHandle(this));
RETURN_TO_LOCAL_UNCHECKED(NewInstance(context), Object);
}
MaybeLocal<v8::Function> FunctionTemplate::GetFunction(Local<Context> context) {
PREPARE_FOR_EXECUTION(context, "v8::FunctionTemplate::GetFunction()",
Function);
auto self = Utils::OpenHandle(this);
Local<Function> result;
has_pending_exception =
!ToLocal<Function>(i::ApiNatives::InstantiateFunction(self), &result);
RETURN_ON_FAILED_EXECUTION(Function);
RETURN_ESCAPED(result);
}
Local<v8::Function> FunctionTemplate::GetFunction() {
i::Handle<i::FunctionTemplateInfo> info = Utils::OpenHandle(this);
i::Isolate* isolate = info->GetIsolate();
ON_BAILOUT(isolate, "v8::FunctionTemplate::GetFunction()",
return Local<v8::Function>());
LOG_API(isolate, "FunctionTemplate::GetFunction");
ENTER_V8(isolate);
EXCEPTION_PREAMBLE(isolate);
i::Handle<i::Object> obj;
has_pending_exception =
!i::ApiNatives::InstantiateFunction(info).ToHandle(&obj);
EXCEPTION_BAILOUT_CHECK(isolate, Local<v8::Function>());
return Utils::ToLocal(i::Handle<i::JSFunction>::cast(obj));
auto context = ContextFromHeapObject(Utils::OpenHandle(this));
RETURN_TO_LOCAL_UNCHECKED(GetFunction(context), Function);
}
bool FunctionTemplate::HasInstance(v8::Handle<v8::Value> value) {
i::Handle<i::FunctionTemplateInfo> info = Utils::OpenHandle(this);
i::Isolate* isolate = info->GetIsolate();
ON_BAILOUT(isolate, "v8::FunctionTemplate::HasInstanceOf()", return false);
i::Object* obj = *Utils::OpenHandle(*value);
return info->IsTemplateFor(obj);
auto self = Utils::OpenHandle(this);
auto obj = Utils::OpenHandle(*value);
return self->IsTemplateFor(*obj);
}
@ -5687,7 +5680,6 @@ inline Local<String> NewString(Isolate* v8_isolate,
String::NewStringType type,
int length) {
i::Isolate* isolate = reinterpret_cast<internal::Isolate*>(v8_isolate);
ON_BAILOUT(isolate, location, return Local<String>());
LOG_API(isolate, env);
if (length == 0) {
return String::Empty(v8_isolate);
@ -6000,13 +5992,9 @@ double v8::Date::ValueOf() const {
void v8::Date::DateTimeConfigurationChangeNotification(Isolate* isolate) {
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
ON_BAILOUT(i_isolate, "v8::Date::DateTimeConfigurationChangeNotification()",
return);
LOG_API(i_isolate, "Date::DateTimeConfigurationChangeNotification");
ENTER_V8(i_isolate);
i_isolate->date_cache()->ResetDateCache();
if (!i_isolate->eternal_handles()->Exists(
i::EternalHandles::DATE_CACHE_VERSION)) {
return;
@ -6035,18 +6023,24 @@ static i::Handle<i::String> RegExpFlagsToString(RegExp::Flags flags) {
}
Local<v8::RegExp> v8::RegExp::New(Handle<String> pattern,
Flags flags) {
i::Isolate* isolate = Utils::OpenHandle(*pattern)->GetIsolate();
LOG_API(isolate, "RegExp::New");
ENTER_V8(isolate);
EXCEPTION_PREAMBLE(isolate);
i::Handle<i::JSRegExp> obj;
has_pending_exception = !i::Execution::NewJSRegExp(
Utils::OpenHandle(*pattern),
RegExpFlagsToString(flags)).ToHandle(&obj);
EXCEPTION_BAILOUT_CHECK(isolate, Local<v8::RegExp>());
return Utils::ToLocal(i::Handle<i::JSRegExp>::cast(obj));
MaybeLocal<v8::RegExp> v8::RegExp::New(Local<Context> context,
Handle<String> pattern, Flags flags) {
PREPARE_FOR_EXECUTION(context, "RegExp::New", RegExp);
Local<v8::RegExp> result;
has_pending_exception =
!ToLocal<RegExp>(i::Execution::NewJSRegExp(Utils::OpenHandle(*pattern),
RegExpFlagsToString(flags)),
&result);
RETURN_ON_FAILED_EXECUTION(RegExp);
RETURN_ESCAPED(result);
}
Local<v8::RegExp> v8::RegExp::New(Handle<String> pattern, Flags flags) {
auto isolate =
reinterpret_cast<Isolate*>(Utils::OpenHandle(*pattern)->GetIsolate());
auto context = isolate->GetCurrentContext();
RETURN_TO_LOCAL_UNCHECKED(New(context, pattern, flags), RegExp);
}
@ -6096,26 +6090,26 @@ uint32_t v8::Array::Length() const {
}
Local<Object> Array::CloneElementAt(uint32_t index) {
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
ON_BAILOUT(isolate, "v8::Array::CloneElementAt()", return Local<Object>());
i::Handle<i::JSObject> self = Utils::OpenHandle(this);
if (!self->HasFastObjectElements()) {
return Local<Object>();
}
MaybeLocal<Object> Array::CloneElementAt(Local<Context> context,
uint32_t index) {
PREPARE_FOR_EXECUTION(context, "v8::Array::CloneElementAt()", Object);
auto self = Utils::OpenHandle(this);
if (!self->HasFastObjectElements()) return Local<Object>();
i::FixedArray* elms = i::FixedArray::cast(self->elements());
i::Object* paragon = elms->get(index);
if (!paragon->IsJSObject()) {
return Local<Object>();
}
if (!paragon->IsJSObject()) return Local<Object>();
i::Handle<i::JSObject> paragon_handle(i::JSObject::cast(paragon));
EXCEPTION_PREAMBLE(isolate);
ENTER_V8(isolate);
i::Handle<i::JSObject> result =
isolate->factory()->CopyJSObject(paragon_handle);
has_pending_exception = result.is_null();
EXCEPTION_BAILOUT_CHECK(isolate, Local<Object>());
return Utils::ToLocal(result);
Local<Object> result;
has_pending_exception = ToLocal<Object>(
isolate->factory()->CopyJSObject(paragon_handle), &result);
RETURN_ON_FAILED_EXECUTION(Object);
RETURN_ESCAPED(result);
}
Local<Object> Array::CloneElementAt(uint32_t index) {
auto context = ContextFromHeapObject(Utils::OpenHandle(this));
RETURN_TO_LOCAL_UNCHECKED(CloneElementAt(context, index), Object);
}
@ -7054,7 +7048,6 @@ bool Isolate::IsDead() {
bool Isolate::AddMessageListener(MessageCallback that, Handle<Value> data) {
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
ON_BAILOUT(isolate, "v8::V8::AddMessageListener()", return false);
ENTER_V8(isolate);
i::HandleScope scope(isolate);
NeanderArray listeners(isolate->factory()->message_listeners());
@ -7069,7 +7062,6 @@ bool Isolate::AddMessageListener(MessageCallback that, Handle<Value> data) {
void Isolate::RemoveMessageListeners(MessageCallback that) {
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
ON_BAILOUT(isolate, "v8::V8::RemoveMessageListeners()", return);
ENTER_V8(isolate);
i::HandleScope scope(isolate);
NeanderArray listeners(isolate->factory()->message_listeners());
@ -7187,7 +7179,6 @@ String::Value::~Value() {
Local<Value> Exception::NAME(v8::Handle<v8::String> raw_message) { \
i::Isolate* isolate = i::Isolate::Current(); \
LOG_API(isolate, #NAME); \
ON_BAILOUT(isolate, "v8::Exception::" #NAME "()", return Local<Value>()); \
ENTER_V8(isolate); \
i::Object* error; \
{ \
@ -7233,7 +7224,6 @@ Local<StackTrace> Exception::GetStackTrace(Handle<Value> exception) {
bool Debug::SetDebugEventListener(EventCallback that, Handle<Value> data) {
i::Isolate* isolate = i::Isolate::Current();
ON_BAILOUT(isolate, "v8::Debug::SetDebugEventListener()", return false);
ENTER_V8(isolate);
i::HandleScope scope(isolate);
i::Handle<i::Object> foreign = isolate->factory()->undefined_value();
@ -7286,52 +7276,54 @@ void Debug::SendCommand(Isolate* isolate,
}
MaybeLocal<Value> Debug::Call(Local<Context> context,
v8::Handle<v8::Function> fun,
v8::Handle<v8::Value> data) {
PREPARE_FOR_EXECUTION(context, "v8::Debug::Call()", Value);
i::Handle<i::Object> data_obj;
if (data.IsEmpty()) {
data_obj = isolate->factory()->undefined_value();
} else {
data_obj = Utils::OpenHandle(*data);
}
Local<Value> result;
has_pending_exception =
!ToLocal<Value>(isolate->debug()->Call(Utils::OpenHandle(*fun), data_obj),
&result);
RETURN_ON_FAILED_EXECUTION(Value);
RETURN_ESCAPED(result);
}
Local<Value> Debug::Call(v8::Handle<v8::Function> fun,
v8::Handle<v8::Value> data) {
i::Isolate* isolate = i::Isolate::Current();
ON_BAILOUT(isolate, "v8::Debug::Call()", return Local<Value>());
ENTER_V8(isolate);
i::MaybeHandle<i::Object> maybe_result;
EXCEPTION_PREAMBLE(isolate);
if (data.IsEmpty()) {
maybe_result = isolate->debug()->Call(
Utils::OpenHandle(*fun), isolate->factory()->undefined_value());
} else {
maybe_result = isolate->debug()->Call(
Utils::OpenHandle(*fun), Utils::OpenHandle(*data));
}
i::Handle<i::Object> result;
has_pending_exception = !maybe_result.ToHandle(&result);
EXCEPTION_BAILOUT_CHECK(isolate, Local<Value>());
return Utils::ToLocal(result);
auto context = ContextFromHeapObject(Utils::OpenHandle(*fun));
RETURN_TO_LOCAL_UNCHECKED(Call(context, fun, data), Value);
}
MaybeLocal<Value> Debug::GetMirror(Local<Context> context,
v8::Handle<v8::Value> obj) {
PREPARE_FOR_EXECUTION(context, "v8::Debug::GetMirror()", Value);
i::Debug* isolate_debug = isolate->debug();
has_pending_exception = !isolate_debug->Load();
RETURN_ON_FAILED_EXECUTION(Value);
i::Handle<i::JSObject> debug(isolate_debug->debug_context()->global_object());
auto name = isolate->factory()->NewStringFromStaticChars("MakeMirror");
auto fun_obj = i::Object::GetProperty(debug, name).ToHandleChecked();
auto v8_fun = Utils::ToLocal(i::Handle<i::JSFunction>::cast(fun_obj));
const int kArgc = 1;
v8::Handle<v8::Value> argv[kArgc] = {obj};
Local<Value> result;
has_pending_exception = !v8_fun->Call(context, Utils::ToLocal(debug), kArgc,
argv).ToLocal(&result);
RETURN_ON_FAILED_EXECUTION(Value);
RETURN_ESCAPED(result);
}
Local<Value> Debug::GetMirror(v8::Handle<v8::Value> obj) {
i::Isolate* isolate = i::Isolate::Current();
ON_BAILOUT(isolate, "v8::Debug::GetMirror()", return Local<Value>());
ENTER_V8(isolate);
v8::EscapableHandleScope scope(reinterpret_cast<Isolate*>(isolate));
i::Debug* isolate_debug = isolate->debug();
EXCEPTION_PREAMBLE(isolate);
has_pending_exception = !isolate_debug->Load();
v8::Local<v8::Value> result;
if (!has_pending_exception) {
i::Handle<i::JSObject> debug(
isolate_debug->debug_context()->global_object());
i::Handle<i::String> name = isolate->factory()->InternalizeOneByteString(
STATIC_CHAR_VECTOR("MakeMirror"));
i::Handle<i::Object> fun_obj =
i::Object::GetProperty(debug, name).ToHandleChecked();
i::Handle<i::JSFunction> fun = i::Handle<i::JSFunction>::cast(fun_obj);
v8::Handle<v8::Function> v8_fun = Utils::ToLocal(fun);
const int kArgc = 1;
v8::Handle<v8::Value> argv[kArgc] = { obj };
result = v8_fun->Call(Utils::ToLocal(debug), kArgc, argv);
has_pending_exception = result.IsEmpty();
}
EXCEPTION_BAILOUT_CHECK(isolate, Local<Value>());
return scope.Escape(result);
RETURN_TO_LOCAL_UNCHECKED(GetMirror(Local<Context>(), obj), Value);
}