Commit b9bf2051 authored by dcarney's avatar dcarney Committed by Commit bot

convert more things to maybe

BUG=v8:3929
LOG=y

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

Cr-Commit-Position: refs/heads/master@{#27038}
parent b2ae7a75
...@@ -1085,7 +1085,9 @@ class V8_EXPORT Script { ...@@ -1085,7 +1085,9 @@ class V8_EXPORT Script {
* context in which it was created (ScriptCompiler::CompileBound or * context in which it was created (ScriptCompiler::CompileBound or
* UnboundScript::BindToCurrentContext()). * UnboundScript::BindToCurrentContext()).
*/ */
// TODO(dcarney): deprecate
Local<Value> Run(); Local<Value> Run();
MaybeLocal<Value> Run(Local<Context> context);
/** /**
* Returns the corresponding context-unbound script. * Returns the corresponding context-unbound script.
...@@ -1398,7 +1400,10 @@ class V8_EXPORT ScriptCompiler { ...@@ -1398,7 +1400,10 @@ class V8_EXPORT ScriptCompiler {
class V8_EXPORT Message { class V8_EXPORT Message {
public: public:
Local<String> Get() const; Local<String> Get() const;
// TODO(dcarney): deprecate
Local<String> GetSourceLine() const; Local<String> GetSourceLine() const;
MaybeLocal<String> GetSourceLine(Local<Context> context) const;
/** /**
* Returns the origin for the script from where the function causing the * Returns the origin for the script from where the function causing the
...@@ -1422,7 +1427,9 @@ class V8_EXPORT Message { ...@@ -1422,7 +1427,9 @@ class V8_EXPORT Message {
/** /**
* Returns the number, 1-based, of the line where the error occurred. * Returns the number, 1-based, of the line where the error occurred.
*/ */
// TODO(dcarney): deprecate
int GetLineNumber() const; int GetLineNumber() const;
Maybe<int> GetLineNumber(Local<Context> context) const;
/** /**
* Returns the index within the script of the first character where * Returns the index within the script of the first character where
...@@ -1440,13 +1447,17 @@ class V8_EXPORT Message { ...@@ -1440,13 +1447,17 @@ class V8_EXPORT Message {
* Returns the index within the line of the first character where * Returns the index within the line of the first character where
* the error occurred. * the error occurred.
*/ */
// TODO(dcarney): deprecate
int GetStartColumn() const; int GetStartColumn() const;
Maybe<int> GetStartColumn(Local<Context> context) const;
/** /**
* Returns the index within the line of the last character where * Returns the index within the line of the last character where
* the error occurred. * the error occurred.
*/ */
// TODO(dcarney): deprecate
int GetEndColumn() const; int GetEndColumn() const;
Maybe<int> GetEndColumn(Local<Context> context) const;
/** /**
* Passes on the value set by the embedder when it fed the script from which * Passes on the value set by the embedder when it fed the script from which
...@@ -1613,7 +1624,9 @@ class V8_EXPORT JSON { ...@@ -1613,7 +1624,9 @@ class V8_EXPORT JSON {
* \param json_string The string to parse. * \param json_string The string to parse.
* \return The corresponding value if successfully parsed. * \return The corresponding value if successfully parsed.
*/ */
// TODO(dcarney): deprecate
static Local<Value> Parse(Local<String> json_string); static Local<Value> Parse(Local<String> json_string);
static MaybeLocal<Value> Parse(Isolate* isolate, Local<String> json_string);
}; };
...@@ -1926,7 +1939,9 @@ class V8_EXPORT Value : public Data { ...@@ -1926,7 +1939,9 @@ class V8_EXPORT Value : public Data {
* Attempts to convert a string to an array index. * Attempts to convert a string to an array index.
* Returns an empty handle if the conversion fails. * Returns an empty handle if the conversion fails.
*/ */
// TODO(dcarney): deprecate.
Local<Uint32> ToArrayIndex() const; Local<Uint32> ToArrayIndex() const;
MaybeLocal<Uint32> ToArrayIndex(Local<Context> context) const;
Maybe<bool> BooleanValue(Local<Context> context) const; Maybe<bool> BooleanValue(Local<Context> context) const;
Maybe<double> NumberValue(Local<Context> context) const; Maybe<double> NumberValue(Local<Context> context) const;
...@@ -1942,7 +1957,9 @@ class V8_EXPORT Value : public Data { ...@@ -1942,7 +1957,9 @@ class V8_EXPORT Value : public Data {
int32_t Int32Value() const; int32_t Int32Value() const;
/** JS == */ /** JS == */
// TODO(dcarney): deprecate.
bool Equals(Handle<Value> that) const; bool Equals(Handle<Value> that) const;
Maybe<bool> Equals(Local<Context> context, Handle<Value> that) const;
bool StrictEquals(Handle<Value> that) const; bool StrictEquals(Handle<Value> that) const;
bool SameValue(Handle<Value> that) const; bool SameValue(Handle<Value> that) const;
......
...@@ -1508,15 +1508,12 @@ int UnboundScript::GetId() { ...@@ -1508,15 +1508,12 @@ int UnboundScript::GetId() {
i::Handle<i::HeapObject> obj = i::Handle<i::HeapObject> obj =
i::Handle<i::HeapObject>::cast(Utils::OpenHandle(this)); i::Handle<i::HeapObject>::cast(Utils::OpenHandle(this));
i::Isolate* isolate = obj->GetIsolate(); i::Isolate* isolate = obj->GetIsolate();
ON_BAILOUT(isolate, "v8::UnboundScript::GetId()", return -1);
LOG_API(isolate, "v8::UnboundScript::GetId"); LOG_API(isolate, "v8::UnboundScript::GetId");
{
i::HandleScope scope(isolate); i::HandleScope scope(isolate);
i::Handle<i::SharedFunctionInfo> function_info( i::Handle<i::SharedFunctionInfo> function_info(
i::SharedFunctionInfo::cast(*obj)); i::SharedFunctionInfo::cast(*obj));
i::Handle<i::Script> script(i::Script::cast(function_info->script())); i::Handle<i::Script> script(i::Script::cast(function_info->script()));
return script->id()->value(); return script->id()->value();
}
} }
...@@ -1524,7 +1521,6 @@ int UnboundScript::GetLineNumber(int code_pos) { ...@@ -1524,7 +1521,6 @@ int UnboundScript::GetLineNumber(int code_pos) {
i::Handle<i::SharedFunctionInfo> obj = i::Handle<i::SharedFunctionInfo> obj =
i::Handle<i::SharedFunctionInfo>::cast(Utils::OpenHandle(this)); i::Handle<i::SharedFunctionInfo>::cast(Utils::OpenHandle(this));
i::Isolate* isolate = obj->GetIsolate(); i::Isolate* isolate = obj->GetIsolate();
ON_BAILOUT(isolate, "v8::UnboundScript::GetLineNumber()", return -1);
LOG_API(isolate, "UnboundScript::GetLineNumber"); LOG_API(isolate, "UnboundScript::GetLineNumber");
if (obj->script()->IsScript()) { if (obj->script()->IsScript()) {
i::Handle<i::Script> script(i::Script::cast(obj->script())); i::Handle<i::Script> script(i::Script::cast(obj->script()));
...@@ -1539,8 +1535,6 @@ Handle<Value> UnboundScript::GetScriptName() { ...@@ -1539,8 +1535,6 @@ Handle<Value> UnboundScript::GetScriptName() {
i::Handle<i::SharedFunctionInfo> obj = i::Handle<i::SharedFunctionInfo> obj =
i::Handle<i::SharedFunctionInfo>::cast(Utils::OpenHandle(this)); i::Handle<i::SharedFunctionInfo>::cast(Utils::OpenHandle(this));
i::Isolate* isolate = obj->GetIsolate(); i::Isolate* isolate = obj->GetIsolate();
ON_BAILOUT(isolate, "v8::UnboundScript::GetName()",
return Handle<String>());
LOG_API(isolate, "UnboundScript::GetName"); LOG_API(isolate, "UnboundScript::GetName");
if (obj->script()->IsScript()) { if (obj->script()->IsScript()) {
i::Object* name = i::Script::cast(obj->script())->name(); i::Object* name = i::Script::cast(obj->script())->name();
...@@ -1555,8 +1549,6 @@ Handle<Value> UnboundScript::GetSourceURL() { ...@@ -1555,8 +1549,6 @@ Handle<Value> UnboundScript::GetSourceURL() {
i::Handle<i::SharedFunctionInfo> obj = i::Handle<i::SharedFunctionInfo> obj =
i::Handle<i::SharedFunctionInfo>::cast(Utils::OpenHandle(this)); i::Handle<i::SharedFunctionInfo>::cast(Utils::OpenHandle(this));
i::Isolate* isolate = obj->GetIsolate(); i::Isolate* isolate = obj->GetIsolate();
ON_BAILOUT(isolate, "v8::UnboundScript::GetSourceURL()",
return Handle<String>());
LOG_API(isolate, "UnboundScript::GetSourceURL"); LOG_API(isolate, "UnboundScript::GetSourceURL");
if (obj->script()->IsScript()) { if (obj->script()->IsScript()) {
i::Object* url = i::Script::cast(obj->script())->source_url(); i::Object* url = i::Script::cast(obj->script())->source_url();
...@@ -1571,8 +1563,6 @@ Handle<Value> UnboundScript::GetSourceMappingURL() { ...@@ -1571,8 +1563,6 @@ Handle<Value> UnboundScript::GetSourceMappingURL() {
i::Handle<i::SharedFunctionInfo> obj = i::Handle<i::SharedFunctionInfo> obj =
i::Handle<i::SharedFunctionInfo>::cast(Utils::OpenHandle(this)); i::Handle<i::SharedFunctionInfo>::cast(Utils::OpenHandle(this));
i::Isolate* isolate = obj->GetIsolate(); i::Isolate* isolate = obj->GetIsolate();
ON_BAILOUT(isolate, "v8::UnboundScript::GetSourceMappingURL()",
return Handle<String>());
LOG_API(isolate, "UnboundScript::GetSourceMappingURL"); LOG_API(isolate, "UnboundScript::GetSourceMappingURL");
if (obj->script()->IsScript()) { if (obj->script()->IsScript()) {
i::Object* url = i::Script::cast(obj->script())->source_mapping_url(); i::Object* url = i::Script::cast(obj->script())->source_mapping_url();
...@@ -1583,26 +1573,28 @@ Handle<Value> UnboundScript::GetSourceMappingURL() { ...@@ -1583,26 +1573,28 @@ Handle<Value> UnboundScript::GetSourceMappingURL() {
} }
Local<Value> Script::Run() { MaybeLocal<Value> Script::Run(Local<Context> context) {
i::Handle<i::Object> obj = Utils::OpenHandle(this, true); PREPARE_FOR_EXECUTION_WITH_CALLBACK(context, "v8::Script::Run()", Value)
// If execution is terminating, Compile(..)->Run() requires this
// check.
if (obj.is_null()) return Local<Value>();
i::Isolate* isolate = i::Handle<i::HeapObject>::cast(obj)->GetIsolate();
ON_BAILOUT(isolate, "v8::Script::Run()", return Local<Value>());
LOG_API(isolate, "Script::Run");
ENTER_V8(isolate);
i::AggregatingHistogramTimerScope timer(isolate->counters()->compile_lazy()); i::AggregatingHistogramTimerScope timer(isolate->counters()->compile_lazy());
i::TimerEventScope<i::TimerEventExecute> timer_scope(isolate); i::TimerEventScope<i::TimerEventExecute> timer_scope(isolate);
i::HandleScope scope(isolate); auto fun = i::Handle<i::JSFunction>::cast(Utils::OpenHandle(this));
i::Handle<i::JSFunction> fun = i::Handle<i::JSFunction>::cast(obj);
EXCEPTION_PREAMBLE(isolate);
i::Handle<i::Object> receiver(isolate->global_proxy(), isolate); i::Handle<i::Object> receiver(isolate->global_proxy(), isolate);
i::Handle<i::Object> result; Local<Value> result;
has_pending_exception = !i::Execution::Call( has_pending_exception =
isolate, fun, receiver, 0, NULL).ToHandle(&result); !ToLocal<Value>(i::Execution::Call(isolate, fun, receiver, 0, NULL),
EXCEPTION_BAILOUT_CHECK_DO_CALLBACK(isolate, Local<Value>()); &result);
return Utils::ToLocal(scope.CloseAndEscape(result)); RETURN_ON_FAILED_EXECUTION(Value);
RETURN_ESCAPED(result);
}
Local<Value> Script::Run() {
auto self = Utils::OpenHandle(this, true);
// If execution is terminating, Compile(..)->Run() requires this
// check.
if (self.is_null()) return Local<Value>();
auto context = ContextFromHeapObject(self);
RETURN_TO_LOCAL_UNCHECKED(Run(context), Value);
} }
...@@ -2176,7 +2168,6 @@ void v8::TryCatch::SetCaptureMessage(bool value) { ...@@ -2176,7 +2168,6 @@ void v8::TryCatch::SetCaptureMessage(bool value) {
Local<String> Message::Get() const { Local<String> Message::Get() const {
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
ON_BAILOUT(isolate, "v8::Message::Get()", return Local<String>());
ENTER_V8(isolate); ENTER_V8(isolate);
EscapableHandleScope scope(reinterpret_cast<Isolate*>(isolate)); EscapableHandleScope scope(reinterpret_cast<Isolate*>(isolate));
i::Handle<i::Object> obj = Utils::OpenHandle(this); i::Handle<i::Object> obj = Utils::OpenHandle(this);
...@@ -2188,12 +2179,9 @@ Local<String> Message::Get() const { ...@@ -2188,12 +2179,9 @@ Local<String> Message::Get() const {
ScriptOrigin Message::GetScriptOrigin() const { ScriptOrigin Message::GetScriptOrigin() const {
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
i::Handle<i::JSMessageObject> message = auto message = i::Handle<i::JSMessageObject>::cast(Utils::OpenHandle(this));
i::Handle<i::JSMessageObject>::cast(Utils::OpenHandle(this)); auto script_wraper = i::Handle<i::Object>(message->script(), isolate);
i::Handle<i::Object> script_wraper = auto script_value = i::Handle<i::JSValue>::cast(script_wraper);
i::Handle<i::Object>(message->script(), isolate);
i::Handle<i::JSValue> script_value =
i::Handle<i::JSValue>::cast(script_wraper);
i::Handle<i::Script> script(i::Script::cast(script_value->value())); i::Handle<i::Script> script(i::Script::cast(script_value->value()));
return GetScriptOriginForScript(isolate, script); return GetScriptOriginForScript(isolate, script);
} }
...@@ -2208,12 +2196,10 @@ v8::Handle<v8::StackTrace> Message::GetStackTrace() const { ...@@ -2208,12 +2196,10 @@ v8::Handle<v8::StackTrace> Message::GetStackTrace() const {
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
ENTER_V8(isolate); ENTER_V8(isolate);
EscapableHandleScope scope(reinterpret_cast<Isolate*>(isolate)); EscapableHandleScope scope(reinterpret_cast<Isolate*>(isolate));
i::Handle<i::JSMessageObject> message = auto message = i::Handle<i::JSMessageObject>::cast(Utils::OpenHandle(this));
i::Handle<i::JSMessageObject>::cast(Utils::OpenHandle(this));
i::Handle<i::Object> stackFramesObj(message->stack_frames(), isolate); i::Handle<i::Object> stackFramesObj(message->stack_frames(), isolate);
if (!stackFramesObj->IsJSArray()) return v8::Handle<v8::StackTrace>(); if (!stackFramesObj->IsJSArray()) return v8::Handle<v8::StackTrace>();
i::Handle<i::JSArray> stackTrace = auto stackTrace = i::Handle<i::JSArray>::cast(stackFramesObj);
i::Handle<i::JSArray>::cast(stackFramesObj);
return scope.Escape(Utils::StackTraceToLocal(stackTrace)); return scope.Escape(Utils::StackTraceToLocal(stackTrace));
} }
...@@ -2237,107 +2223,102 @@ MUST_USE_RESULT static i::MaybeHandle<i::Object> CallV8HeapFunction( ...@@ -2237,107 +2223,102 @@ MUST_USE_RESULT static i::MaybeHandle<i::Object> CallV8HeapFunction(
} }
int Message::GetLineNumber() const { Maybe<int> Message::GetLineNumber(Local<Context> context) const {
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); PREPARE_FOR_EXECUTION_PRIMITIVE(context, "v8::Message::GetLineNumber()", int);
ON_BAILOUT(isolate, "v8::Message::GetLineNumber()", return kNoLineNumberInfo);
ENTER_V8(isolate);
i::HandleScope scope(isolate);
EXCEPTION_PREAMBLE(isolate);
i::Handle<i::Object> result; i::Handle<i::Object> result;
has_pending_exception = has_pending_exception =
!CallV8HeapFunction(isolate, "GetLineNumber", Utils::OpenHandle(this)) !CallV8HeapFunction(isolate, "GetLineNumber", Utils::OpenHandle(this))
.ToHandle(&result); .ToHandle(&result);
EXCEPTION_BAILOUT_CHECK(isolate, 0); RETURN_ON_FAILED_EXECUTION_PRIMITIVE(int);
return static_cast<int>(result->Number()); return Just(static_cast<int>(result->Number()));
}
int Message::GetLineNumber() const {
auto context = ContextFromHeapObject(Utils::OpenHandle(this));
return GetLineNumber(context).FromMaybe(0);
} }
int Message::GetStartPosition() const { int Message::GetStartPosition() const {
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); auto self = Utils::OpenHandle(this);
ENTER_V8(isolate); return self->start_position();
i::HandleScope scope(isolate);
i::Handle<i::JSMessageObject> message =
i::Handle<i::JSMessageObject>::cast(Utils::OpenHandle(this));
return message->start_position();
} }
int Message::GetEndPosition() const { int Message::GetEndPosition() const {
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); auto self = Utils::OpenHandle(this);
ENTER_V8(isolate); return self->end_position();
i::HandleScope scope(isolate); }
i::Handle<i::JSMessageObject> message =
i::Handle<i::JSMessageObject>::cast(Utils::OpenHandle(this));
return message->end_position(); Maybe<int> Message::GetStartColumn(Local<Context> context) const {
PREPARE_FOR_EXECUTION_PRIMITIVE(context, "v8::Message::GetStartColumn()",
int);
auto self = Utils::OpenHandle(this);
i::Handle<i::Object> start_col_obj;
has_pending_exception = !CallV8HeapFunction(isolate, "GetPositionInLine",
self).ToHandle(&start_col_obj);
RETURN_ON_FAILED_EXECUTION_PRIMITIVE(int);
return Just(static_cast<int>(start_col_obj->Number()));
} }
int Message::GetStartColumn() const { int Message::GetStartColumn() const {
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); auto context = ContextFromHeapObject(Utils::OpenHandle(this));
ON_BAILOUT(isolate, "v8::Message::GetStartColumn()", return kNoColumnInfo); const int default_value = kNoColumnInfo;
ENTER_V8(isolate); return GetStartColumn(context).FromMaybe(default_value);
i::HandleScope scope(isolate); }
i::Handle<i::JSObject> data_obj = Utils::OpenHandle(this);
EXCEPTION_PREAMBLE(isolate);
Maybe<int> Message::GetEndColumn(Local<Context> context) const {
PREPARE_FOR_EXECUTION_PRIMITIVE(context, "v8::Message::GetEndColumn()", int);
auto self = Utils::OpenHandle(this);
i::Handle<i::Object> start_col_obj; i::Handle<i::Object> start_col_obj;
has_pending_exception = has_pending_exception = !CallV8HeapFunction(isolate, "GetPositionInLine",
!CallV8HeapFunction(isolate, "GetPositionInLine", data_obj) self).ToHandle(&start_col_obj);
.ToHandle(&start_col_obj); RETURN_ON_FAILED_EXECUTION_PRIMITIVE(int);
EXCEPTION_BAILOUT_CHECK(isolate, 0); int start = self->start_position();
return static_cast<int>(start_col_obj->Number()); int end = self->end_position();
return Just(static_cast<int>(start_col_obj->Number()) + (end - start));
} }
int Message::GetEndColumn() const { int Message::GetEndColumn() const {
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); auto context = ContextFromHeapObject(Utils::OpenHandle(this));
ON_BAILOUT(isolate, "v8::Message::GetEndColumn()", return kNoColumnInfo); const int default_value = kNoColumnInfo;
ENTER_V8(isolate); return GetEndColumn(context).FromMaybe(default_value);
i::HandleScope scope(isolate);
i::Handle<i::JSObject> data_obj = Utils::OpenHandle(this);
EXCEPTION_PREAMBLE(isolate);
i::Handle<i::Object> start_col_obj;
has_pending_exception =
!CallV8HeapFunction(isolate, "GetPositionInLine", data_obj)
.ToHandle(&start_col_obj);
EXCEPTION_BAILOUT_CHECK(isolate, 0);
i::Handle<i::JSMessageObject> message =
i::Handle<i::JSMessageObject>::cast(data_obj);
int start = message->start_position();
int end = message->end_position();
return static_cast<int>(start_col_obj->Number()) + (end - start);
} }
bool Message::IsSharedCrossOrigin() const { bool Message::IsSharedCrossOrigin() const {
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
ENTER_V8(isolate); ENTER_V8(isolate);
i::HandleScope scope(isolate); auto self = Utils::OpenHandle(this);
i::Handle<i::JSMessageObject> message = auto script = i::Handle<i::JSValue>::cast(
i::Handle<i::JSMessageObject>::cast(Utils::OpenHandle(this)); i::Handle<i::Object>(self->script(), isolate));
i::Handle<i::JSValue> script =
i::Handle<i::JSValue>::cast(i::Handle<i::Object>(message->script(),
isolate));
return i::Script::cast(script->value())->is_shared_cross_origin(); return i::Script::cast(script->value())->is_shared_cross_origin();
} }
Local<String> Message::GetSourceLine() const { MaybeLocal<String> Message::GetSourceLine(Local<Context> context) const {
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); PREPARE_FOR_EXECUTION(context, "v8::Message::GetSourceLine()", String);
ON_BAILOUT(isolate, "v8::Message::GetSourceLine()", return Local<String>());
ENTER_V8(isolate);
EscapableHandleScope scope(reinterpret_cast<Isolate*>(isolate));
EXCEPTION_PREAMBLE(isolate);
i::Handle<i::Object> result; i::Handle<i::Object> result;
has_pending_exception = has_pending_exception =
!CallV8HeapFunction(isolate, "GetSourceLine", Utils::OpenHandle(this)) !CallV8HeapFunction(isolate, "GetSourceLine", Utils::OpenHandle(this))
.ToHandle(&result); .ToHandle(&result);
EXCEPTION_BAILOUT_CHECK(isolate, Local<v8::String>()); RETURN_ON_FAILED_EXECUTION(String);
Local<String> str;
if (result->IsString()) { if (result->IsString()) {
return scope.Escape(Utils::ToLocal(i::Handle<i::String>::cast(result))); str = Utils::ToLocal(i::Handle<i::String>::cast(result));
} else {
return Local<String>();
} }
RETURN_ESCAPED(str);
}
Local<String> Message::GetSourceLine() const {
auto context = ContextFromHeapObject(Utils::OpenHandle(this));
RETURN_TO_LOCAL_UNCHECKED(GetSourceLine(context), String)
} }
...@@ -2354,24 +2335,19 @@ Local<StackFrame> StackTrace::GetFrame(uint32_t index) const { ...@@ -2354,24 +2335,19 @@ Local<StackFrame> StackTrace::GetFrame(uint32_t index) const {
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
ENTER_V8(isolate); ENTER_V8(isolate);
EscapableHandleScope scope(reinterpret_cast<Isolate*>(isolate)); EscapableHandleScope scope(reinterpret_cast<Isolate*>(isolate));
i::Handle<i::JSArray> self = Utils::OpenHandle(this); auto self = Utils::OpenHandle(this);
i::Handle<i::Object> obj = auto obj = i::Object::GetElement(isolate, self, index).ToHandleChecked();
i::Object::GetElement(isolate, self, index).ToHandleChecked(); auto jsobj = i::Handle<i::JSObject>::cast(obj);
i::Handle<i::JSObject> jsobj = i::Handle<i::JSObject>::cast(obj);
return scope.Escape(Utils::StackFrameToLocal(jsobj)); return scope.Escape(Utils::StackFrameToLocal(jsobj));
} }
int StackTrace::GetFrameCount() const { int StackTrace::GetFrameCount() const {
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
ENTER_V8(isolate);
return i::Smi::cast(Utils::OpenHandle(this)->length())->value(); return i::Smi::cast(Utils::OpenHandle(this)->length())->value();
} }
Local<Array> StackTrace::AsArray() { Local<Array> StackTrace::AsArray() {
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
ENTER_V8(isolate);
return Utils::ToLocal(Utils::OpenHandle(this)); return Utils::ToLocal(Utils::OpenHandle(this));
} }
...@@ -2564,21 +2540,25 @@ bool NativeWeakMap::Delete(Handle<Value> v8_key) { ...@@ -2564,21 +2540,25 @@ bool NativeWeakMap::Delete(Handle<Value> v8_key) {
// --- J S O N --- // --- J S O N ---
Local<Value> JSON::Parse(Local<String> json_string) { MaybeLocal<Value> JSON::Parse(Isolate* v8_isolate, Local<String> json_string) {
auto isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
PREPARE_FOR_EXECUTION_WITH_ISOLATE(isolate, "JSON::Parse", Value);
i::Handle<i::String> string = Utils::OpenHandle(*json_string); i::Handle<i::String> string = Utils::OpenHandle(*json_string);
i::Isolate* isolate = string->GetIsolate();
ENTER_V8(isolate);
i::HandleScope scope(isolate);
i::Handle<i::String> source = i::String::Flatten(string); i::Handle<i::String> source = i::String::Flatten(string);
EXCEPTION_PREAMBLE(isolate); auto maybe = source->IsSeqOneByteString()
i::MaybeHandle<i::Object> maybe_result = ? i::JsonParser<true>::Parse(source)
source->IsSeqOneByteString() ? i::JsonParser<true>::Parse(source)
: i::JsonParser<false>::Parse(source); : i::JsonParser<false>::Parse(source);
i::Handle<i::Object> result; Local<Value> result;
has_pending_exception = !maybe_result.ToHandle(&result); has_pending_exception = !ToLocal<Value>(maybe, &result);
EXCEPTION_BAILOUT_CHECK(isolate, Local<Object>()); RETURN_ON_FAILED_EXECUTION(Value);
return Utils::ToLocal( RETURN_ESCAPED(result);
i::Handle<i::Object>::cast(scope.CloseAndEscape(result))); }
Local<Value> JSON::Parse(Local<String> json_string) {
auto isolate = reinterpret_cast<v8::Isolate*>(
Utils::OpenHandle(*json_string)->GetIsolate());
RETURN_TO_LOCAL_UNCHECKED(Parse(isolate, json_string), Value);
} }
...@@ -3228,20 +3208,17 @@ uint32_t Value::Uint32Value() const { ...@@ -3228,20 +3208,17 @@ uint32_t Value::Uint32Value() const {
} }
Local<Uint32> Value::ToArrayIndex() const { MaybeLocal<Uint32> Value::ToArrayIndex(Local<Context> context) const {
i::Handle<i::Object> obj = Utils::OpenHandle(this); auto self = Utils::OpenHandle(this);
if (obj->IsSmi()) { if (self->IsSmi()) {
if (i::Smi::cast(*obj)->value() >= 0) return Utils::Uint32ToLocal(obj); if (i::Smi::cast(*self)->value() >= 0) return Utils::Uint32ToLocal(self);
return Local<Uint32>(); return Local<Uint32>();
} }
i::Isolate* isolate = i::HeapObject::cast(*obj)->GetIsolate(); PREPARE_FOR_EXECUTION(context, "ToArrayIndex", Uint32);
LOG_API(isolate, "ToArrayIndex");
ENTER_V8(isolate);
EXCEPTION_PREAMBLE(isolate);
i::Handle<i::Object> string_obj; i::Handle<i::Object> string_obj;
has_pending_exception = !i::Execution::ToString( has_pending_exception =
isolate, obj).ToHandle(&string_obj); !i::Execution::ToString(isolate, self).ToHandle(&string_obj);
EXCEPTION_BAILOUT_CHECK(isolate, Local<Uint32>()); RETURN_ON_FAILED_EXECUTION(Uint32);
i::Handle<i::String> str = i::Handle<i::String>::cast(string_obj); i::Handle<i::String> str = i::Handle<i::String>::cast(string_obj);
uint32_t index; uint32_t index;
if (str->AsArrayIndex(&index)) { if (str->AsArrayIndex(&index)) {
...@@ -3251,56 +3228,65 @@ Local<Uint32> Value::ToArrayIndex() const { ...@@ -3251,56 +3228,65 @@ Local<Uint32> Value::ToArrayIndex() const {
} else { } else {
value = isolate->factory()->NewNumber(index); value = isolate->factory()->NewNumber(index);
} }
return Utils::Uint32ToLocal(value); RETURN_ESCAPED(Utils::Uint32ToLocal(value));
} }
return Local<Uint32>(); return Local<Uint32>();
} }
bool Value::Equals(Handle<Value> that) const { Local<Uint32> Value::ToArrayIndex() const {
i::Handle<i::Object> obj = Utils::OpenHandle(this, true); auto self = Utils::OpenHandle(this);
i::Handle<i::Object> other = Utils::OpenHandle(*that); if (self->IsSmi()) {
if (obj->IsSmi() && other->IsSmi()) { if (i::Smi::cast(*self)->value() >= 0) return Utils::Uint32ToLocal(self);
return obj->Number() == other->Number(); return Local<Uint32>();
} }
i::Object* ho = obj->IsSmi() ? *other : *obj; auto context = ContextFromHeapObject(self);
i::Isolate* isolate = i::HeapObject::cast(ho)->GetIsolate(); RETURN_TO_LOCAL_UNCHECKED(ToArrayIndex(context), Uint32);
if (!Utils::ApiCheck(!obj.is_null() && !that.IsEmpty(), }
"v8::Value::Equals()",
"Reading from empty handle")) {
return false; Maybe<bool> Value::Equals(Local<Context> context, Handle<Value> that) const {
auto self = Utils::OpenHandle(this);
auto other = Utils::OpenHandle(*that);
if (self->IsSmi() && other->IsSmi()) {
return Just(self->Number() == other->Number());
} }
LOG_API(isolate, "Equals"); if (self->IsJSObject() && other->IsJSObject()) {
ENTER_V8(isolate); return Just(*self == *other);
// If both obj and other are JSObjects, we'd better compare by identity
// immediately when going into JS builtin. The reason is Invoke
// would overwrite global object receiver with global proxy.
if (obj->IsJSObject() && other->IsJSObject()) {
return *obj == *other;
} }
PREPARE_FOR_EXECUTION_PRIMITIVE(context, "v8::Value::Equals()", bool);
i::Handle<i::Object> args[] = { other }; i::Handle<i::Object> args[] = { other };
EXCEPTION_PREAMBLE(isolate);
i::Handle<i::Object> result; i::Handle<i::Object> result;
has_pending_exception = has_pending_exception =
!CallV8HeapFunction(isolate, "EQUALS", obj, arraysize(args), args) !CallV8HeapFunction(isolate, "EQUALS", self, arraysize(args), args)
.ToHandle(&result); .ToHandle(&result);
EXCEPTION_BAILOUT_CHECK(isolate, false); RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool);
return *result == i::Smi::FromInt(i::EQUAL); return Just(*result == i::Smi::FromInt(i::EQUAL));
}
bool Value::Equals(Handle<Value> that) const {
auto self = Utils::OpenHandle(this);
auto other = Utils::OpenHandle(*that);
if (self->IsSmi() && other->IsSmi()) {
return self->Number() == other->Number();
}
if (self->IsJSObject() && other->IsJSObject()) {
return *self == *other;
}
auto heap_object = self->IsSmi() ? other : self;
auto context = ContextFromHeapObject(heap_object);
return Equals(context, that).FromMaybe(false);
} }
bool Value::StrictEquals(Handle<Value> that) const { bool Value::StrictEquals(Handle<Value> that) const {
i::Handle<i::Object> obj = Utils::OpenHandle(this, true); i::Handle<i::Object> obj = Utils::OpenHandle(this);
i::Handle<i::Object> other = Utils::OpenHandle(*that); i::Handle<i::Object> other = Utils::OpenHandle(*that);
if (obj->IsSmi()) { if (obj->IsSmi()) {
return other->IsNumber() && obj->Number() == other->Number(); return other->IsNumber() && obj->Number() == other->Number();
} }
i::Isolate* isolate = i::HeapObject::cast(*obj)->GetIsolate(); i::Isolate* isolate = i::HeapObject::cast(*obj)->GetIsolate();
if (!Utils::ApiCheck(!obj.is_null() && !that.IsEmpty(),
"v8::Value::StrictEquals()",
"Reading from empty handle")) {
return false;
}
LOG_API(isolate, "StrictEquals"); LOG_API(isolate, "StrictEquals");
// Must check HeapNumber first, since NaN !== NaN. // Must check HeapNumber first, since NaN !== NaN.
if (obj->IsHeapNumber()) { if (obj->IsHeapNumber()) {
...@@ -3326,14 +3312,9 @@ bool Value::StrictEquals(Handle<Value> that) const { ...@@ -3326,14 +3312,9 @@ bool Value::StrictEquals(Handle<Value> that) const {
bool Value::SameValue(Handle<Value> that) const { bool Value::SameValue(Handle<Value> that) const {
i::Handle<i::Object> obj = Utils::OpenHandle(this, true); auto self = Utils::OpenHandle(this);
if (!Utils::ApiCheck(!obj.is_null() && !that.IsEmpty(), auto other = Utils::OpenHandle(*that);
"v8::Value::SameValue()", return self->SameValue(*other);
"Reading from empty handle")) {
return false;
}
i::Handle<i::Object> other = Utils::OpenHandle(*that);
return obj->SameValue(*other);
} }
...@@ -3859,7 +3840,6 @@ void Object::SetAccessorProperty(Local<Name> name, ...@@ -3859,7 +3840,6 @@ void Object::SetAccessorProperty(Local<Name> name,
// TODO(verwaest): Remove |settings|. // TODO(verwaest): Remove |settings|.
DCHECK_EQ(v8::DEFAULT, settings); DCHECK_EQ(v8::DEFAULT, settings);
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
ON_BAILOUT(isolate, "v8::Object::SetAccessorProperty()", return);
ENTER_V8(isolate); ENTER_V8(isolate);
i::HandleScope scope(isolate); i::HandleScope scope(isolate);
i::Handle<i::Object> getter_i = v8::Utils::OpenHandle(*getter); i::Handle<i::Object> getter_i = v8::Utils::OpenHandle(*getter);
...@@ -4553,11 +4533,7 @@ Local<v8::Value> Function::GetBoundFunction() const { ...@@ -4553,11 +4533,7 @@ Local<v8::Value> Function::GetBoundFunction() const {
int Name::GetIdentityHash() { int Name::GetIdentityHash() {
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); auto self = Utils::OpenHandle(this);
ON_BAILOUT(isolate, "v8::Name::GetIdentityHash()", return 0);
ENTER_V8(isolate);
i::HandleScope scope(isolate);
i::Handle<i::Name> self = Utils::OpenHandle(this);
return static_cast<int>(self->Hash()); return static_cast<int>(self->Hash());
} }
...@@ -5522,8 +5498,6 @@ Local<Context> v8::Context::New( ...@@ -5522,8 +5498,6 @@ Local<Context> v8::Context::New(
void v8::Context::SetSecurityToken(Handle<Value> token) { void v8::Context::SetSecurityToken(Handle<Value> token) {
i::Handle<i::Context> env = Utils::OpenHandle(this); i::Handle<i::Context> env = Utils::OpenHandle(this);
i::Isolate* isolate = env->GetIsolate();
ENTER_V8(isolate);
i::Handle<i::Object> token_handle = Utils::OpenHandle(*token); i::Handle<i::Object> token_handle = Utils::OpenHandle(*token);
env->set_security_token(*token_handle); env->set_security_token(*token_handle);
} }
...@@ -5531,8 +5505,6 @@ void v8::Context::SetSecurityToken(Handle<Value> token) { ...@@ -5531,8 +5505,6 @@ void v8::Context::SetSecurityToken(Handle<Value> token) {
void v8::Context::UseDefaultSecurityToken() { void v8::Context::UseDefaultSecurityToken() {
i::Handle<i::Context> env = Utils::OpenHandle(this); i::Handle<i::Context> env = Utils::OpenHandle(this);
i::Isolate* isolate = env->GetIsolate();
ENTER_V8(isolate);
env->set_security_token(env->global_object()); env->set_security_token(env->global_object());
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment