【发布时间】:2017-02-12 08:23:15
【问题描述】:
我试图弄清楚一些 Javascript 原生函数和运算符(速记函数)是如何在 Chrome 的 V8 中实现的。特别是,我试图了解一元 (-) 操作的工作原理。
我在V8中找到unary operators的代码here
有人能解释一下这里发生了什么吗:
Type* Typer::Visitor::JSTypeOfTyper(Type* type, Typer* t) {
Factory* const f = t->isolate()->factory();
if (type->Is(Type::Boolean())) {
return Type::Constant(f->boolean_string(), t->zone());
} else if (type->Is(Type::Number())) {
return Type::Constant(f->number_string(), t->zone());
} else if (type->Is(Type::String())) {
return Type::Constant(f->string_string(), t->zone());
} else if (type->Is(Type::Symbol())) {
return Type::Constant(f->symbol_string(), t->zone());
} else if (type->Is(Type::Union(Type::Undefined(), Type::OtherUndetectable(),
t->zone()))) {
return Type::Constant(f->undefined_string(), t->zone());
} else if (type->Is(Type::Null())) {
return Type::Constant(f->object_string(), t->zone());
} else if (type->Is(Type::Function())) {
return Type::Constant(f->function_string(), t->zone());
} else if (type->IsConstant()) {
return Type::Constant(
Object::TypeOf(t->isolate(), type->AsConstant()->Value()), t->zone());
}
return Type::InternalizedString();
}
Type* Typer::Visitor::TypeJSTypeOf(Node* node) {
return TypeUnaryOp(node, JSTypeOfTyper);
}
我完全没有 C++ 的背景,因为我是一名 Web 开发人员,所以我似乎无法理解发生了什么。谢谢!
【问题讨论】:
-
我猜如果没有 v8 架构的谷歌知识,没有人可以解释这里发生了什么。你到底为什么要挖这么深?
-
这里的问题是,如果不深入了解 v8 实现,就无法回答这个问题。很明显,该代码标识了
type的类型并对其进行了相应的表示。如需更多解释,请联系开发人员,或研究文档v8docs.nodesource.com
标签: javascript c++ google-chrome v8 chromium