| Index: src/api.cc
|
| diff --git a/src/api.cc b/src/api.cc
|
| index 36434cd02193ec69cad227330892f38caf7c5a97..4e6fd99b710360340f46240fa2d5dbb73e6e789f 100644
|
| --- a/src/api.cc
|
| +++ b/src/api.cc
|
| @@ -1980,7 +1980,8 @@ MaybeLocal<Function> ScriptCompiler::CompileFunctionInContext(
|
| Utils::OpenHandle(*v8_context->Global()), 0,
|
| nullptr).ToHandle(&result);
|
| RETURN_ON_FAILED_EXECUTION(Function);
|
| - RETURN_ESCAPED(Utils::ToLocal(i::Handle<i::JSFunction>::cast(result)));
|
| + RETURN_ESCAPED(
|
| + Utils::FunctionToLocal(i::Handle<i::JSFunction>::cast(result)));
|
| }
|
|
|
|
|
| @@ -2698,9 +2699,7 @@ bool Value::IsFalse() const {
|
| }
|
|
|
|
|
| -bool Value::IsFunction() const {
|
| - return Utils::OpenHandle(this)->IsJSFunction();
|
| -}
|
| +bool Value::IsFunction() const { return Utils::OpenHandle(this)->IsCallable(); }
|
|
|
|
|
| bool Value::IsName() const {
|
| @@ -3039,8 +3038,7 @@ void v8::Object::CheckCast(Value* that) {
|
|
|
| void v8::Function::CheckCast(Value* that) {
|
| i::Handle<i::Object> obj = Utils::OpenHandle(that);
|
| - Utils::ApiCheck(obj->IsJSFunction(),
|
| - "v8::Function::Cast()",
|
| + Utils::ApiCheck(obj->IsCallable(), "v8::Function::Cast()",
|
| "Could not convert to function");
|
| }
|
|
|
| @@ -4342,8 +4340,8 @@ MaybeLocal<Object> Function::NewInstance(Local<Context> context, int argc,
|
| STATIC_ASSERT(sizeof(v8::Local<v8::Value>) == sizeof(i::Object**));
|
| i::Handle<i::Object>* args = reinterpret_cast<i::Handle<i::Object>*>(argv);
|
| Local<Object> result;
|
| - has_pending_exception =
|
| - !ToLocal<Object>(i::Execution::New(self, argc, args), &result);
|
| + has_pending_exception = !ToLocal<Object>(
|
| + i::Execution::New(isolate, self, self, argc, args), &result);
|
| RETURN_ON_FAILED_EXECUTION(Object);
|
| RETURN_ESCAPED(result);
|
| }
|
| @@ -4381,20 +4379,32 @@ Local<v8::Value> Function::Call(v8::Local<v8::Value> recv, int argc,
|
|
|
|
|
| void Function::SetName(v8::Local<v8::String> name) {
|
| - i::Handle<i::JSFunction> func = Utils::OpenHandle(this);
|
| + auto self = Utils::OpenHandle(this);
|
| + if (!self->IsJSFunction()) return;
|
| + auto func = i::Handle<i::JSFunction>::cast(self);
|
| func->shared()->set_name(*Utils::OpenHandle(*name));
|
| }
|
|
|
|
|
| Local<Value> Function::GetName() const {
|
| - i::Handle<i::JSFunction> func = Utils::OpenHandle(this);
|
| + auto self = Utils::OpenHandle(this);
|
| + if (!self->IsJSFunction()) {
|
| + return ToApiHandle<Primitive>(
|
| + self->GetIsolate()->factory()->undefined_value());
|
| + }
|
| + auto func = i::Handle<i::JSFunction>::cast(self);
|
| return Utils::ToLocal(i::Handle<i::Object>(func->shared()->name(),
|
| func->GetIsolate()));
|
| }
|
|
|
|
|
| Local<Value> Function::GetInferredName() const {
|
| - i::Handle<i::JSFunction> func = Utils::OpenHandle(this);
|
| + auto self = Utils::OpenHandle(this);
|
| + if (!self->IsJSFunction()) {
|
| + return ToApiHandle<Primitive>(
|
| + self->GetIsolate()->factory()->undefined_value());
|
| + }
|
| + auto func = i::Handle<i::JSFunction>::cast(self);
|
| return Utils::ToLocal(i::Handle<i::Object>(func->shared()->inferred_name(),
|
| func->GetIsolate()));
|
| }
|
| @@ -4403,7 +4413,11 @@ Local<Value> Function::GetInferredName() const {
|
| Local<Value> Function::GetDisplayName() const {
|
| i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
|
| ENTER_V8(isolate);
|
| - i::Handle<i::JSFunction> func = Utils::OpenHandle(this);
|
| + auto self = Utils::OpenHandle(this);
|
| + if (!self->IsJSFunction()) {
|
| + return ToApiHandle<Primitive>(isolate->factory()->undefined_value());
|
| + }
|
| + auto func = i::Handle<i::JSFunction>::cast(self);
|
| i::Handle<i::String> property_name =
|
| isolate->factory()->NewStringFromStaticChars("displayName");
|
| i::Handle<i::Object> value =
|
| @@ -4417,7 +4431,11 @@ Local<Value> Function::GetDisplayName() const {
|
|
|
|
|
| ScriptOrigin Function::GetScriptOrigin() const {
|
| - i::Handle<i::JSFunction> func = Utils::OpenHandle(this);
|
| + auto self = Utils::OpenHandle(this);
|
| + if (!self->IsJSFunction()) {
|
| + return v8::ScriptOrigin(Local<Value>());
|
| + }
|
| + auto func = i::Handle<i::JSFunction>::cast(self);
|
| if (func->shared()->script()->IsScript()) {
|
| i::Handle<i::Script> script(i::Script::cast(func->shared()->script()));
|
| return GetScriptOriginForScript(func->GetIsolate(), script);
|
| @@ -4430,7 +4448,11 @@ const int Function::kLineOffsetNotFound = -1;
|
|
|
|
|
| int Function::GetScriptLineNumber() const {
|
| - i::Handle<i::JSFunction> func = Utils::OpenHandle(this);
|
| + auto self = Utils::OpenHandle(this);
|
| + if (!self->IsJSFunction()) {
|
| + return kLineOffsetNotFound;
|
| + }
|
| + auto func = i::Handle<i::JSFunction>::cast(self);
|
| if (func->shared()->script()->IsScript()) {
|
| i::Handle<i::Script> script(i::Script::cast(func->shared()->script()));
|
| return i::Script::GetLineNumber(script, func->shared()->start_position());
|
| @@ -4440,7 +4462,11 @@ int Function::GetScriptLineNumber() const {
|
|
|
|
|
| int Function::GetScriptColumnNumber() const {
|
| - i::Handle<i::JSFunction> func = Utils::OpenHandle(this);
|
| + auto self = Utils::OpenHandle(this);
|
| + if (!self->IsJSFunction()) {
|
| + return kLineOffsetNotFound;
|
| + }
|
| + auto func = i::Handle<i::JSFunction>::cast(self);
|
| if (func->shared()->script()->IsScript()) {
|
| i::Handle<i::Script> script(i::Script::cast(func->shared()->script()));
|
| return i::Script::GetColumnNumber(script, func->shared()->start_position());
|
| @@ -4450,13 +4476,21 @@ int Function::GetScriptColumnNumber() const {
|
|
|
|
|
| bool Function::IsBuiltin() const {
|
| - i::Handle<i::JSFunction> func = Utils::OpenHandle(this);
|
| + auto self = Utils::OpenHandle(this);
|
| + if (!self->IsJSFunction()) {
|
| + return false;
|
| + }
|
| + auto func = i::Handle<i::JSFunction>::cast(self);
|
| return func->IsBuiltin();
|
| }
|
|
|
|
|
| int Function::ScriptId() const {
|
| - i::Handle<i::JSFunction> func = Utils::OpenHandle(this);
|
| + auto self = Utils::OpenHandle(this);
|
| + if (!self->IsJSFunction()) {
|
| + return v8::UnboundScript::kNoScriptId;
|
| + }
|
| + auto func = i::Handle<i::JSFunction>::cast(self);
|
| if (!func->shared()->script()->IsScript()) {
|
| return v8::UnboundScript::kNoScriptId;
|
| }
|
| @@ -4466,7 +4500,11 @@ int Function::ScriptId() const {
|
|
|
|
|
| Local<v8::Value> Function::GetBoundFunction() const {
|
| - i::Handle<i::JSFunction> func = Utils::OpenHandle(this);
|
| + auto self = Utils::OpenHandle(this);
|
| + if (!self->IsJSFunction()) {
|
| + return v8::Undefined(reinterpret_cast<v8::Isolate*>(self->GetIsolate()));
|
| + }
|
| + auto func = i::Handle<i::JSFunction>::cast(self);
|
| if (!func->shared()->bound()) {
|
| return v8::Undefined(reinterpret_cast<v8::Isolate*>(func->GetIsolate()));
|
| }
|
| @@ -4474,7 +4512,7 @@ Local<v8::Value> Function::GetBoundFunction() const {
|
| i::BindingsArray::cast(func->function_bindings()));
|
| i::Handle<i::Object> original(bound_args->bound_function(),
|
| func->GetIsolate());
|
| - return Utils::ToLocal(i::Handle<i::JSFunction>::cast(original));
|
| + return Utils::FunctionToLocal(i::Handle<i::JSFunction>::cast(original));
|
| }
|
|
|
|
|
| @@ -7702,7 +7740,7 @@ MaybeLocal<Value> Debug::GetMirror(Local<Context> context,
|
| 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));
|
| + auto v8_fun = Utils::FunctionToLocal(i::Handle<i::JSFunction>::cast(fun_obj));
|
| const int kArgc = 1;
|
| v8::Local<v8::Value> argv[kArgc] = {obj};
|
| Local<Value> result;
|
|
|