![](/img/trans.png)
[英]How to use the same context across multiple functions in v8 Javascript?
[英]How do native Javascript functions work in V8?
我試圖弄清楚如何在Chrome V8的后台實現某些Javascript本機函數和運算符(速記函數)。 特別是,我試圖了解一元(-)操作的工作方式。
我在這里找到了V8中unary operators
的代碼
有人可以解釋這里發生的事情:
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開發人員,所以我似乎無法理解正在發生的事情。 謝謝!
我認為-
變成-1
乘法。
SRC /解析/ parser.cc
// The same idea for '-foo' => 'foo*(-1)'.
if (op == Token::SUB) {
return factory()->NewBinaryOperation(
Token::MUL, expression, factory()->NewNumberLiteral(-1, pos), pos);
}
你想在你想了解什么更詳細地說-
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.