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

Unified Diff: src/api.cc

Issue 993223003: convert most remaining api functions needing context to maybes (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 9 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « include/v8-debug.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/api.cc
diff --git a/src/api.cc b/src/api.cc
index 020335a587adb9e44dd0325fec64705265a4865f..e7667ba006fd38a553f78265b0e40502fadaf4df 100644
--- a/src/api.cc
+++ b/src/api.cc
@@ -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(
}
+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 =
+ !ToLocal<Object>(i::ApiNatives::InstantiateObject(self), &result);
+ RETURN_ON_FAILED_EXECUTION(Object);
+ RETURN_ESCAPED(result);
+}
+
+
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;
+ 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 =
- !i::ApiNatives::InstantiateObject(info).ToHandle(&obj);
- EXCEPTION_BAILOUT_CHECK(isolate, Local<v8::Object>());
- return Utils::ToLocal(i::Handle<i::JSObject>::cast(obj));
+ !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,
}
-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);
+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()) {
- maybe_result = isolate->debug()->Call(
- Utils::OpenHandle(*fun), isolate->factory()->undefined_value());
+ data_obj = isolate->factory()->undefined_value();
} else {
- maybe_result = isolate->debug()->Call(
- Utils::OpenHandle(*fun), Utils::OpenHandle(*data));
+ data_obj = 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);
+ 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::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));
+Local<Value> Debug::Call(v8::Handle<v8::Function> fun,
+ v8::Handle<v8::Value> data) {
+ 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();
- 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_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) {
+ RETURN_TO_LOCAL_UNCHECKED(GetMirror(Local<Context>(), obj), Value);
}
« no previous file with comments | « include/v8-debug.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698