Begin porting CallSite to C++

Review-Url: https://codereview.chromium.org/2158303002
Cr-Commit-Position: refs/heads/master@{#37975}
This commit is contained in:
jgruber 2016-07-22 03:12:24 -07:00 committed by Commit bot
parent 428dde9ac7
commit c8a0dce96c
9 changed files with 473 additions and 227 deletions

View File

@ -876,6 +876,7 @@ v8_source_set("v8_base") {
"src/builtins/builtins-array.cc",
"src/builtins/builtins-arraybuffer.cc",
"src/builtins/builtins-boolean.cc",
"src/builtins/builtins-callsite.cc",
"src/builtins/builtins-dataview.cc",
"src/builtins/builtins-date.cc",
"src/builtins/builtins-error.cc",

View File

@ -434,19 +434,21 @@ Handle<JSFunction> SimpleCreateFunction(Isolate* isolate, Handle<String> name,
Handle<JSFunction> SimpleInstallFunction(Handle<JSObject> base,
Handle<String> name,
Builtins::Name call, int len,
bool adapt) {
bool adapt,
PropertyAttributes attrs = DONT_ENUM) {
Handle<JSFunction> fun =
SimpleCreateFunction(base->GetIsolate(), name, call, len, adapt);
InstallFunction(base, fun, name, DONT_ENUM);
InstallFunction(base, fun, name, attrs);
return fun;
}
Handle<JSFunction> SimpleInstallFunction(Handle<JSObject> base,
const char* name, Builtins::Name call,
int len, bool adapt) {
int len, bool adapt,
PropertyAttributes attrs = DONT_ENUM) {
Factory* const factory = base->GetIsolate()->factory();
return SimpleInstallFunction(base, factory->InternalizeUtf8String(name), call,
len, adapt);
len, adapt, attrs);
}
Handle<JSFunction> SimpleInstallGetter(Handle<JSObject> base,
@ -2632,6 +2634,57 @@ void Bootstrapper::ExportFromRuntime(Isolate* isolate,
async_function_throw->shared()->set_native(false);
}
}
{ // -- C a l l S i t e
// Builtin functions for CallSite.
Handle<JSFunction> callsite_fun = InstallFunction(
container, "CallSite", JS_OBJECT_TYPE, JSObject::kHeaderSize,
isolate->initial_object_prototype(), Builtins::kCallSiteConstructor);
callsite_fun->shared()->DontAdaptArguments();
callsite_fun->shared()->set_native(true);
{
Handle<JSObject> proto =
factory->NewJSObject(isolate->object_function(), TENURED);
JSObject::AddProperty(proto, factory->constructor_string(), callsite_fun,
DONT_ENUM);
struct FunctionInfo {
const char* name;
Builtins::Name id;
};
FunctionInfo infos[] = {
{"getColumnNumber", Builtins::kCallSitePrototypeGetColumnNumber},
{"getEvalOrigin", Builtins::kCallSitePrototypeGetEvalOrigin},
{"getFileName", Builtins::kCallSitePrototypeGetFileName},
{"getFunction", Builtins::kCallSitePrototypeGetFunction},
{"getFunctionName", Builtins::kCallSitePrototypeGetFunctionName},
{"getLineNumber", Builtins::kCallSitePrototypeGetLineNumber},
{"getMethodName", Builtins::kCallSitePrototypeGetMethodName},
{"getPosition", Builtins::kCallSitePrototypeGetPosition},
{"getScriptNameOrSourceURL",
Builtins::kCallSitePrototypeGetScriptNameOrSourceURL},
{"getThis", Builtins::kCallSitePrototypeGetThis},
{"getTypeName", Builtins::kCallSitePrototypeGetTypeName},
{"isConstructor", Builtins::kCallSitePrototypeIsConstructor},
{"isEval", Builtins::kCallSitePrototypeIsEval},
{"isNative", Builtins::kCallSitePrototypeIsNative},
{"isToplevel", Builtins::kCallSitePrototypeIsToplevel}};
PropertyAttributes attrs =
static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE | READ_ONLY);
Handle<JSFunction> fun;
for (const FunctionInfo& info : infos) {
fun = SimpleInstallFunction(proto, info.name, info.id, 0, true, attrs);
fun->shared()->set_native(true);
}
Accessors::FunctionSetPrototype(callsite_fun, proto).Assert();
}
}
}

View File

@ -0,0 +1,389 @@
// Copyright 2016 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "src/builtins/builtins.h"
#include "src/builtins/builtins-utils.h"
#include "src/string-builder.h"
#include "src/wasm/wasm-module.h"
namespace v8 {
namespace internal {
#define CHECK_CALLSITE(recv, method) \
CHECK_RECEIVER(JSObject, recv, method); \
if (!JSReceiver::HasOwnProperty( \
recv, isolate->factory()->call_site_position_symbol()) \
.FromMaybe(false)) { \
THROW_NEW_ERROR_RETURN_FAILURE( \
isolate, \
NewTypeError(MessageTemplate::kCallSiteMethod, \
isolate->factory()->NewStringFromAsciiChecked(method))); \
}
#define SET_CALLSITE_PROPERTY(target, key, value) \
RETURN_FAILURE_ON_EXCEPTION( \
isolate, JSObject::SetOwnPropertyIgnoreAttributes( \
target, isolate->factory()->key(), value, DONT_ENUM))
BUILTIN(CallSiteConstructor) {
HandleScope scope(isolate);
Handle<JSFunction> target = args.target<JSFunction>();
Handle<HeapObject> new_target_obj = args.new_target();
Handle<Object> receiver = args.atOrUndefined(isolate, 1);
Handle<Object> fun = args.atOrUndefined(isolate, 2);
Handle<Object> pos = args.atOrUndefined(isolate, 3);
Handle<Object> strict_mode = args.atOrUndefined(isolate, 4);
// Create the JS object.
Handle<JSReceiver> new_target = new_target_obj->IsJSReceiver()
? Handle<JSReceiver>::cast(new_target_obj)
: Handle<JSReceiver>::cast(target);
Handle<JSObject> obj;
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, obj,
JSObject::New(target, new_target));
// For wasm frames, receiver is the wasm object and fun is the function index
// instead of an actual function.
const bool is_wasm_object =
receiver->IsJSObject() && wasm::IsWasmObject(JSObject::cast(*receiver));
if (!fun->IsJSFunction() && !is_wasm_object) {
THROW_NEW_ERROR_RETURN_FAILURE(
isolate, NewTypeError(MessageTemplate::kCallSiteExpectsFunction,
Object::TypeOf(isolate, receiver),
Object::TypeOf(isolate, fun)));
}
if (is_wasm_object) {
DCHECK(!fun->IsJSFunction());
SET_CALLSITE_PROPERTY(obj, call_site_wasm_obj_symbol, receiver);
Handle<Object> fun_index;
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, fun_index,
Object::ToUint32(isolate, fun));
SET_CALLSITE_PROPERTY(obj, call_site_wasm_func_index_symbol, fun);
} else {
DCHECK(fun->IsJSFunction());
SET_CALLSITE_PROPERTY(obj, call_site_receiver_symbol, receiver);
SET_CALLSITE_PROPERTY(obj, call_site_function_symbol, fun);
}
Handle<Object> pos_int32;
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, pos_int32,
Object::ToInt32(isolate, pos));
SET_CALLSITE_PROPERTY(obj, call_site_position_symbol, pos_int32);
SET_CALLSITE_PROPERTY(
obj, call_site_strict_symbol,
isolate->factory()->ToBoolean(strict_mode->BooleanValue()));
return *obj;
}
#undef SET_CALLSITE_PROPERTY
namespace {
Object* PositiveNumberOrNull(int value, Isolate* isolate) {
if (value >= 0) return *isolate->factory()->NewNumberFromInt(value);
return isolate->heap()->null_value();
}
} // namespace
BUILTIN(CallSitePrototypeGetColumnNumber) {
HandleScope scope(isolate);
CHECK_CALLSITE(recv, "getColumnNumber");
CallSite call_site(isolate, recv);
CHECK(call_site.IsJavaScript() || call_site.IsWasm());
return PositiveNumberOrNull(call_site.GetColumnNumber(), isolate);
}
namespace {
Object* EvalFromFunctionName(Isolate* isolate, Handle<Script> script) {
if (script->eval_from_shared()->IsUndefined(isolate))
return *isolate->factory()->undefined_value();
Handle<SharedFunctionInfo> shared(
SharedFunctionInfo::cast(script->eval_from_shared()));
// Find the name of the function calling eval.
if (shared->name()->BooleanValue()) {
return shared->name();
}
return shared->inferred_name();
}
Object* EvalFromScript(Isolate* isolate, Handle<Script> script) {
if (script->eval_from_shared()->IsUndefined(isolate))
return *isolate->factory()->undefined_value();
Handle<SharedFunctionInfo> eval_from_shared(
SharedFunctionInfo::cast(script->eval_from_shared()));
return eval_from_shared->script()->IsScript()
? eval_from_shared->script()
: *isolate->factory()->undefined_value();
}
MaybeHandle<String> FormatEvalOrigin(Isolate* isolate, Handle<Script> script) {
Handle<Object> sourceURL = Script::GetNameOrSourceURL(script);
if (!sourceURL->IsUndefined(isolate)) {
DCHECK(sourceURL->IsString());
return Handle<String>::cast(sourceURL);
}
IncrementalStringBuilder builder(isolate);
builder.AppendCString("eval at ");
Handle<Object> eval_from_function_name =
handle(EvalFromFunctionName(isolate, script), isolate);
if (eval_from_function_name->BooleanValue()) {
Handle<String> str;
ASSIGN_RETURN_ON_EXCEPTION(
isolate, str, Object::ToString(isolate, eval_from_function_name),
String);
builder.AppendString(str);
} else {
builder.AppendCString("<anonymous>");
}
Handle<Object> eval_from_script_obj =
handle(EvalFromScript(isolate, script), isolate);
if (eval_from_script_obj->IsScript()) {
Handle<Script> eval_from_script =
Handle<Script>::cast(eval_from_script_obj);
builder.AppendCString(" (");
if (eval_from_script->compilation_type() == Script::COMPILATION_TYPE_EVAL) {
// Eval script originated from another eval.
Handle<String> str;
ASSIGN_RETURN_ON_EXCEPTION(
isolate, str, FormatEvalOrigin(isolate, eval_from_script), String);
builder.AppendString(str);
} else {
DCHECK(eval_from_script->compilation_type() !=
Script::COMPILATION_TYPE_EVAL);
// eval script originated from "real" source.
Handle<Object> name_obj = handle(eval_from_script->name(), isolate);
if (eval_from_script->name()->IsString()) {
builder.AppendString(Handle<String>::cast(name_obj));
Script::PositionInfo info;
if (eval_from_script->GetPositionInfo(script->GetEvalPosition(), &info,
Script::NO_OFFSET)) {
builder.AppendCString(":");
Handle<String> str = isolate->factory()->NumberToString(
handle(Smi::FromInt(info.line + 1), isolate));
builder.AppendString(str);
builder.AppendCString(":");
str = isolate->factory()->NumberToString(
handle(Smi::FromInt(info.column + 1), isolate));
builder.AppendString(str);
}
} else {
DCHECK(!eval_from_script->name()->IsString());
builder.AppendCString("unknown source");
}
}
builder.AppendCString(")");
}
Handle<String> result;
ASSIGN_RETURN_ON_EXCEPTION(isolate, result, builder.Finish(), String);
return result;
}
} // namespace
BUILTIN(CallSitePrototypeGetEvalOrigin) {
HandleScope scope(isolate);
CHECK_CALLSITE(recv, "getEvalOrigin");
CallSite call_site(isolate, recv);
if (call_site.IsWasm()) return *isolate->factory()->undefined_value();
// Retrieve the function's script object.
Handle<Object> function_obj;
Handle<Symbol> symbol = isolate->factory()->call_site_function_symbol();
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, function_obj,
JSObject::GetProperty(recv, symbol));
DCHECK(function_obj->IsJSFunction());
Handle<JSFunction> function = Handle<JSFunction>::cast(function_obj);
Handle<Object> script = handle(function->shared()->script(), isolate);
RETURN_RESULT_OR_FAILURE(
isolate, FormatEvalOrigin(isolate, Handle<Script>::cast(script)));
}
BUILTIN(CallSitePrototypeGetFileName) {
HandleScope scope(isolate);
CHECK_CALLSITE(recv, "getFileName");
CallSite call_site(isolate, recv);
CHECK(call_site.IsJavaScript() || call_site.IsWasm());
return *call_site.GetFileName();
}
namespace {
bool CallSiteIsStrict(Isolate* isolate, Handle<JSObject> receiver) {
Handle<Object> strict;
Handle<Symbol> symbol = isolate->factory()->call_site_strict_symbol();
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, strict,
JSObject::GetProperty(receiver, symbol));
return strict->BooleanValue();
}
} // namespace
BUILTIN(CallSitePrototypeGetFunction) {
HandleScope scope(isolate);
CHECK_CALLSITE(recv, "getFunction");
if (CallSiteIsStrict(isolate, recv))
return *isolate->factory()->undefined_value();
Handle<Symbol> symbol = isolate->factory()->call_site_function_symbol();
RETURN_RESULT_OR_FAILURE(isolate, JSObject::GetProperty(recv, symbol));
}
BUILTIN(CallSitePrototypeGetFunctionName) {
HandleScope scope(isolate);
CHECK_CALLSITE(recv, "getFunctionName");
CallSite call_site(isolate, recv);
CHECK(call_site.IsJavaScript() || call_site.IsWasm());
return *call_site.GetFunctionName();
}
BUILTIN(CallSitePrototypeGetLineNumber) {
HandleScope scope(isolate);
CHECK_CALLSITE(recv, "getLineNumber");
CallSite call_site(isolate, recv);
CHECK(call_site.IsJavaScript() || call_site.IsWasm());
int line_number = call_site.IsWasm() ? call_site.wasm_func_index()
: call_site.GetLineNumber();
return PositiveNumberOrNull(line_number, isolate);
}
BUILTIN(CallSitePrototypeGetMethodName) {
HandleScope scope(isolate);
CHECK_CALLSITE(recv, "getMethodName");
CallSite call_site(isolate, recv);
CHECK(call_site.IsJavaScript() || call_site.IsWasm());
return *call_site.GetMethodName();
}
BUILTIN(CallSitePrototypeGetPosition) {
HandleScope scope(isolate);
CHECK_CALLSITE(recv, "getPosition");
Handle<Symbol> symbol = isolate->factory()->call_site_position_symbol();
RETURN_RESULT_OR_FAILURE(isolate, JSObject::GetProperty(recv, symbol));
}
BUILTIN(CallSitePrototypeGetScriptNameOrSourceURL) {
HandleScope scope(isolate);
CHECK_CALLSITE(recv, "getScriptNameOrSourceUrl");
CallSite call_site(isolate, recv);
CHECK(call_site.IsJavaScript() || call_site.IsWasm());
return *call_site.GetScriptNameOrSourceUrl();
}
BUILTIN(CallSitePrototypeGetThis) {
HandleScope scope(isolate);
CHECK_CALLSITE(recv, "getThis");
if (CallSiteIsStrict(isolate, recv))
return *isolate->factory()->undefined_value();
Handle<Object> receiver;
Handle<Symbol> symbol = isolate->factory()->call_site_receiver_symbol();
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, receiver,
JSObject::GetProperty(recv, symbol));
if (*receiver == isolate->heap()->call_site_constructor_symbol())
return *isolate->factory()->undefined_value();
return *receiver;
}
BUILTIN(CallSitePrototypeGetTypeName) {
HandleScope scope(isolate);
CHECK_CALLSITE(recv, "getTypeName");
Handle<Object> receiver;
Handle<Symbol> symbol = isolate->factory()->call_site_receiver_symbol();
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, receiver,
JSObject::GetProperty(recv, symbol));
// TODO(jgruber): Check for strict/constructor here as above.
if (receiver->IsNull(isolate) || receiver->IsUndefined(isolate))
return *isolate->factory()->null_value();
if (receiver->IsJSProxy()) return *isolate->factory()->Proxy_string();
Handle<JSReceiver> receiver_object =
Object::ToObject(isolate, receiver).ToHandleChecked();
return *JSReceiver::GetConstructorName(receiver_object);
}
BUILTIN(CallSitePrototypeIsConstructor) {
HandleScope scope(isolate);
CHECK_CALLSITE(recv, "isConstructor");
CallSite call_site(isolate, recv);
CHECK(call_site.IsJavaScript() || call_site.IsWasm());
return isolate->heap()->ToBoolean(call_site.IsConstructor());
}
BUILTIN(CallSitePrototypeIsEval) {
HandleScope scope(isolate);
CHECK_CALLSITE(recv, "isEval");
CallSite call_site(isolate, recv);
CHECK(call_site.IsJavaScript() || call_site.IsWasm());
return isolate->heap()->ToBoolean(call_site.IsEval());
}
BUILTIN(CallSitePrototypeIsNative) {
HandleScope scope(isolate);
CHECK_CALLSITE(recv, "isNative");
CallSite call_site(isolate, recv);
CHECK(call_site.IsJavaScript() || call_site.IsWasm());
return isolate->heap()->ToBoolean(call_site.IsNative());
}
BUILTIN(CallSitePrototypeIsToplevel) {
HandleScope scope(isolate);
CHECK_CALLSITE(recv, "isToplevel");
CallSite call_site(isolate, recv);
CHECK(call_site.IsJavaScript() || call_site.IsWasm());
return isolate->heap()->ToBoolean(call_site.IsToplevel());
}
BUILTIN(CallSitePrototypeToString) {
HandleScope scope(isolate);
// TODO(jgruber)
return *isolate->factory()->undefined_value();
}
#undef CHECK_CALLSITE
} // namespace internal
} // namespace v8

View File

@ -211,6 +211,25 @@ namespace internal {
/* ES6 section 19.3.3.3 Boolean.prototype.valueOf ( ) */ \
TFJ(BooleanPrototypeValueOf, 1) \
\
/* CallSite */ \
CPP(CallSiteConstructor) \
CPP(CallSitePrototypeGetColumnNumber) \
CPP(CallSitePrototypeGetEvalOrigin) \
CPP(CallSitePrototypeGetFileName) \
CPP(CallSitePrototypeGetFunction) \
CPP(CallSitePrototypeGetFunctionName) \
CPP(CallSitePrototypeGetLineNumber) \
CPP(CallSitePrototypeGetMethodName) \
CPP(CallSitePrototypeGetPosition) \
CPP(CallSitePrototypeGetScriptNameOrSourceURL) \
CPP(CallSitePrototypeGetThis) \
CPP(CallSitePrototypeGetTypeName) \
CPP(CallSitePrototypeIsConstructor) \
CPP(CallSitePrototypeIsEval) \
CPP(CallSitePrototypeIsNative) \
CPP(CallSitePrototypeIsToplevel) \
CPP(CallSitePrototypeToString) \
\
/* DataView */ \
CPP(DataViewConstructor) \
CPP(DataViewConstructor_ConstructStub) \

View File

@ -15,6 +15,7 @@ var ArrayJoin;
var Bool16x8ToString;
var Bool32x4ToString;
var Bool8x16ToString;
var CallSite = utils.ImportNow("CallSite");
var callSiteConstructorSymbol =
utils.ImportNow("call_site_constructor_symbol");
var callSiteReceiverSymbol =
@ -271,121 +272,6 @@ function GetStackTraceLine(recv, fun, pos, isGlobal) {
// ----------------------------------------------------------------------------
// Error implementation
function CallSite(receiver, fun, pos, strict_mode) {
// For wasm frames, receiver is the wasm object and fun is the function index
// instead of an actual function.
if (!IS_FUNCTION(fun) && !%IsWasmObject(receiver)) {
throw MakeTypeError(kCallSiteExpectsFunction, typeof receiver, typeof fun);
}
if (IS_UNDEFINED(new.target)) {
return new CallSite(receiver, fun, pos, strict_mode);
}
if (IS_FUNCTION(fun)) {
SET_PRIVATE(this, callSiteReceiverSymbol, receiver);
SET_PRIVATE(this, callSiteFunctionSymbol, fun);
} else {
SET_PRIVATE(this, callSiteWasmObjectSymbol, receiver);
SET_PRIVATE(this, callSiteWasmFunctionIndexSymbol, TO_UINT32(fun));
}
SET_PRIVATE(this, callSitePositionSymbol, TO_INT32(pos));
SET_PRIVATE(this, callSiteStrictSymbol, TO_BOOLEAN(strict_mode));
}
function CheckCallSite(obj, name) {
if (!IS_RECEIVER(obj) || !HAS_PRIVATE(obj, callSitePositionSymbol)) {
throw MakeTypeError(kCallSiteMethod, name);
}
}
function CallSiteGetThis() {
CheckCallSite(this, "getThis");
if (GET_PRIVATE(this, callSiteStrictSymbol)) {
return UNDEFINED;
}
var recv = GET_PRIVATE(this, callSiteReceiverSymbol);
return (recv == callSiteConstructorSymbol) ? UNDEFINED : recv;
}
function CallSiteGetFunction() {
CheckCallSite(this, "getFunction");
return GET_PRIVATE(this, callSiteStrictSymbol)
? UNDEFINED : GET_PRIVATE(this, callSiteFunctionSymbol);
}
function CallSiteGetPosition() {
CheckCallSite(this, "getPosition");
return GET_PRIVATE(this, callSitePositionSymbol);
}
function CallSiteGetTypeName() {
CheckCallSite(this, "getTypeName");
return GetTypeName(GET_PRIVATE(this, callSiteReceiverSymbol), false);
}
function CallSiteIsToplevel() {
CheckCallSite(this, "isTopLevel");
return %CallSiteIsToplevelRT(this);
}
function CallSiteIsEval() {
CheckCallSite(this, "isEval");
return %CallSiteIsEvalRT(this);
}
function CallSiteGetEvalOrigin() {
CheckCallSite(this, "getEvalOrigin");
var script = %FunctionGetScript(GET_PRIVATE(this, callSiteFunctionSymbol));
return FormatEvalOrigin(script);
}
function CallSiteGetScriptNameOrSourceURL() {
CheckCallSite(this, "getScriptNameOrSourceURL");
return %CallSiteGetScriptNameOrSourceUrlRT(this);
}
function CallSiteGetFunctionName() {
// See if the function knows its own name
CheckCallSite(this, "getFunctionName");
return %CallSiteGetFunctionNameRT(this);
}
function CallSiteGetMethodName() {
// See if we can find a unique property on the receiver that holds
// this function.
CheckCallSite(this, "getMethodName");
return %CallSiteGetMethodNameRT(this);
}
function CallSiteGetFileName() {
CheckCallSite(this, "getFileName");
return %CallSiteGetFileNameRT(this);
}
function CallSiteGetLineNumber() {
if (HAS_PRIVATE(this, callSiteWasmObjectSymbol)) {
return GET_PRIVATE(this, callSiteWasmFunctionIndexSymbol);
}
CheckCallSite(this, "getLineNumber");
return %CallSiteGetLineNumberRT(this);
}
function CallSiteGetColumnNumber() {
CheckCallSite(this, "getColumnNumber");
return %CallSiteGetColumnNumberRT(this);
}
function CallSiteIsNative() {
CheckCallSite(this, "isNative");
return %CallSiteIsNativeRT(this);
}
function CallSiteIsConstructor() {
CheckCallSite(this, "isConstructor");
return %CallSiteIsConstructorRT(this);
}
function CallSiteToString() {
if (HAS_PRIVATE(this, callSiteWasmObjectSymbol)) {
var funName = this.getFunctionName();
@ -459,63 +345,9 @@ function CallSiteToString() {
return line;
}
utils.SetUpLockedPrototype(CallSite, ["receiver", "fun", "pos"], [
"getThis", CallSiteGetThis,
"getTypeName", CallSiteGetTypeName,
"isToplevel", CallSiteIsToplevel,
"isEval", CallSiteIsEval,
"getEvalOrigin", CallSiteGetEvalOrigin,
"getScriptNameOrSourceURL", CallSiteGetScriptNameOrSourceURL,
"getFunction", CallSiteGetFunction,
"getFunctionName", CallSiteGetFunctionName,
"getMethodName", CallSiteGetMethodName,
"getFileName", CallSiteGetFileName,
"getLineNumber", CallSiteGetLineNumber,
"getColumnNumber", CallSiteGetColumnNumber,
"isNative", CallSiteIsNative,
"getPosition", CallSiteGetPosition,
"isConstructor", CallSiteIsConstructor,
"toString", CallSiteToString
]);
function FormatEvalOrigin(script) {
var sourceURL = script.nameOrSourceURL();
if (sourceURL) {
return sourceURL;
}
var eval_origin = "eval at ";
if (script.eval_from_function_name) {
eval_origin += script.eval_from_function_name;
} else {
eval_origin += "<anonymous>";
}
var eval_from_script = script.eval_from_script;
if (eval_from_script) {
if (eval_from_script.compilation_type == COMPILATION_TYPE_EVAL) {
// eval script originated from another eval.
eval_origin += " (" + FormatEvalOrigin(eval_from_script) + ")";
} else {
// eval script originated from "real" source.
if (eval_from_script.name) {
eval_origin += " (" + eval_from_script.name;
var location = eval_from_script.locationFromPosition(
script.eval_from_script_position, true);
if (location) {
eval_origin += ":" + (location.line + 1);
eval_origin += ":" + (location.column + 1);
}
eval_origin += ")";
} else {
eval_origin += " (unknown source)";
}
}
}
return eval_origin;
}
%AddNamedProperty(CallSite.prototype, "toString", CallSiteToString,
DONT_ENUM | DONT_DELETE | READ_ONLY);
%SetNativeFlag(CallSiteToString);
function FormatErrorString(error) {

View File

@ -62,6 +62,8 @@ class CallSite {
bool IsJavaScript() { return !fun_.is_null(); }
bool IsWasm() { return !wasm_obj_.is_null(); }
int wasm_func_index() const { return wasm_func_index_; }
private:
Isolate* isolate_;
Handle<Object> receiver_;

View File

@ -394,47 +394,6 @@ RUNTIME_FUNCTION(Runtime_FormatMessageString) {
template_index, arg0, arg1, arg2));
}
#define CALLSITE_GET(NAME, RETURN) \
RUNTIME_FUNCTION(Runtime_CallSite##NAME##RT) { \
HandleScope scope(isolate); \
DCHECK(args.length() == 1); \
CONVERT_ARG_HANDLE_CHECKED(JSObject, call_site_obj, 0); \
Handle<String> result; \
CallSite call_site(isolate, call_site_obj); \
CHECK(call_site.IsJavaScript() || call_site.IsWasm()); \
return RETURN(call_site.NAME(), isolate); \
}
static inline Object* ReturnDereferencedHandle(Handle<Object> obj,
Isolate* isolate) {
return *obj;
}
static inline Object* ReturnPositiveNumberOrNull(int value, Isolate* isolate) {
if (value >= 0) return *isolate->factory()->NewNumberFromInt(value);
return isolate->heap()->null_value();
}
static inline Object* ReturnBoolean(bool value, Isolate* isolate) {
return isolate->heap()->ToBoolean(value);
}
CALLSITE_GET(GetFileName, ReturnDereferencedHandle)
CALLSITE_GET(GetFunctionName, ReturnDereferencedHandle)
CALLSITE_GET(GetScriptNameOrSourceUrl, ReturnDereferencedHandle)
CALLSITE_GET(GetMethodName, ReturnDereferencedHandle)
CALLSITE_GET(GetLineNumber, ReturnPositiveNumberOrNull)
CALLSITE_GET(GetColumnNumber, ReturnPositiveNumberOrNull)
CALLSITE_GET(IsNative, ReturnBoolean)
CALLSITE_GET(IsToplevel, ReturnBoolean)
CALLSITE_GET(IsEval, ReturnBoolean)
CALLSITE_GET(IsConstructor, ReturnBoolean)
#undef CALLSITE_GET
RUNTIME_FUNCTION(Runtime_IS_VAR) {
UNREACHABLE(); // implemented as macro in the parser

View File

@ -311,16 +311,6 @@ namespace internal {
F(MessageGetStartPosition, 1, 1) \
F(MessageGetScript, 1, 1) \
F(FormatMessageString, 4, 1) \
F(CallSiteGetFileNameRT, 1, 1) \
F(CallSiteGetFunctionNameRT, 1, 1) \
F(CallSiteGetScriptNameOrSourceUrlRT, 1, 1) \
F(CallSiteGetMethodNameRT, 1, 1) \
F(CallSiteGetLineNumberRT, 1, 1) \
F(CallSiteGetColumnNumberRT, 1, 1) \
F(CallSiteIsNativeRT, 1, 1) \
F(CallSiteIsToplevelRT, 1, 1) \
F(CallSiteIsEvalRT, 1, 1) \
F(CallSiteIsConstructorRT, 1, 1) \
F(IS_VAR, 1, 1) \
F(ThrowConstructedNonConstructable, 1, 1) \
F(ThrowDerivedConstructorReturnedNonObject, 0, 1) \

View File

@ -489,6 +489,7 @@
'builtins/builtins-arraybuffer.cc',
'builtins/builtins-array.cc',
'builtins/builtins-boolean.cc',
'builtins/builtins-callsite.cc',
'builtins/builtins-dataview.cc',
'builtins/builtins-date.cc',
'builtins/builtins-error.cc',