我找不到此功能的任何说明。
即使在v8来源分析后,我仍然不清楚,因为
它以“RETURN_NATIVE_CALL(to_detail_string...
”结尾,我在我的来源中找不到to_detail_string
。
这里应该是关于这个功能的文档: https://v8docs.nodesource.com/io.js-3.0/dc/d0a/classv8_1_1_value.html#a2f9770296dc2c8d274bc8cc0dca243e5
从v8源复制/粘贴:
V8_WARN_UNUSED_RESULT MaybeLocal<String> ToDetailString(
Local<Context> context) const;
MaybeLocal<String> Value::ToDetailString(Local<Context> context) const {
auto obj = Utils::OpenHandle(this);
if (obj->IsString()) return ToApiHandle<String>(obj);
PREPARE_FOR_EXECUTION(context, "ToDetailString", String);
Local<String> result;
has_pending_exception =
!ToLocal<String>(i::Execution::ToDetailString(isolate, obj), &result);
RETURN_ON_FAILED_EXECUTION(String);
RETURN_ESCAPED(result);
}
MaybeHandle<Object> Execution::ToDetailString(
Isolate* isolate, Handle<Object> obj) {
RETURN_NATIVE_CALL(to_detail_string, { obj });
}
有人可以提供文档的任何提示或链接吗?
我可以调用它并查看结果,但我希望答案中包含一些有用的信息和链接。
答案 0 :(得分:1)
这是在ToDetailString的messages.js中实现的。
答案 1 :(得分:0)
v8 / src / messages.js中的函数定义:
function ToDetailString(obj) {
if (obj != null && IS_OBJECT(obj) && obj.toString === ObjectToString) {
var constructor = obj.constructor;
if (typeof constructor == "function") {
var constructorName = constructor.name;
if (IS_STRING(constructorName) && constructorName !== "") {
return "#<" + constructorName + ">";
}
}
}
return ToStringCheckErrorObject(obj);
}
另见此处讨论的片段:
http://logs.nodejs.org/v8/2013-02-05
ToDetailString prints #<constructor name> if the object to be printed
doesn't have a custom toString method.
ToString prints [object <class of object>].
ToDetailString also handles error objects differently.