mirror of
https://github.com/RGBCube/serenity
synced 2025-05-16 20:15:07 +00:00
LibJS: Implement typeof operator
This commit is contained in:
parent
0a71533aff
commit
46a897b59b
4 changed files with 27 additions and 1 deletions
|
@ -199,6 +199,23 @@ Value UnaryExpression::execute(Interpreter& interpreter) const
|
|||
return bitwise_not(lhs_result);
|
||||
case UnaryOp::Not:
|
||||
return Value(!lhs_result.to_boolean());
|
||||
case UnaryOp::Typeof:
|
||||
switch (lhs_result.type()) {
|
||||
case Value::Type::Undefined:
|
||||
return js_string(interpreter.heap(), "undefined");
|
||||
case Value::Type::Null:
|
||||
// yes, this is on purpose. yes, this is how javascript works.
|
||||
// yes, it's silly.
|
||||
return js_string(interpreter.heap(), "object");
|
||||
case Value::Type::Number:
|
||||
return js_string(interpreter.heap(), "number");
|
||||
case Value::Type::String:
|
||||
return js_string(interpreter.heap(), "string");
|
||||
case Value::Type::Object:
|
||||
return js_string(interpreter.heap(), "object");
|
||||
case Value::Type::Boolean:
|
||||
return js_string(interpreter.heap(), "boolean");
|
||||
}
|
||||
}
|
||||
|
||||
ASSERT_NOT_REACHED();
|
||||
|
@ -318,6 +335,9 @@ void UnaryExpression::dump(int indent) const
|
|||
case UnaryOp::Not:
|
||||
op_string = "!";
|
||||
break;
|
||||
case UnaryOp::Typeof:
|
||||
op_string = "typeof ";
|
||||
break;
|
||||
}
|
||||
|
||||
print_indent(indent);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue