njs_object_prototype_value_of(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
njs_index_t unused)
{
- vm->retval = args[0];
+ vm->retval = *njs_argument(args, 0);
+
+ if (!njs_is_object(&vm->retval)) {
+ return njs_value_to_object(vm, &vm->retval);
+ }
return NJS_OK;
}
{ njs_str("Object.prototype.valueOf.prototype"),
njs_str("undefined") },
+ { njs_str("Object.prototype.valueOf.call()"),
+ njs_str("TypeError: cannot convert null or undefined to object") },
+
+ { njs_str("Object.prototype.valueOf.call(null)"),
+ njs_str("TypeError: cannot convert null or undefined to object") },
+
+ { njs_str("[false, NaN, Symbol(), '']"
+ ".map((x) => Object.prototype.valueOf.call(x))"
+ ".map((x) => Object.prototype.toString.call(x))"),
+ njs_str("[object Boolean],[object Number],[object Symbol],[object String]") },
+
{ njs_str("Object.constructor === Function"),
njs_str("true") },