/*
- * The __proto__ property of booleans, numbers and strings primitives
- * and Boolean.prototype, Number.prototype, and String.prototype objects.
+ * The __proto__ property of booleans, numbers and strings primitives,
+ * of objects created by Boolean(), Number(), and String() constructors,
+ * and of Boolean.prototype, Number.prototype, and String.prototype objects.
*/
njs_ret_t
njs_primitive_prototype_get_proto(njs_vm_t *vm, njs_value_t *value)
{
- nxt_uint_t index;
+ njs_object_t *proto;
/*
* The __proto__ getters reside in object prototypes of primitive types
- * and have to return different results for primitive type and for object
- * prototype.
+ * and have to return different results for primitive type and for objects.
*/
- index = njs_is_object(value) ? NJS_PROTOTYPE_OBJECT:
- njs_primitive_prototype_index(value->type);
+ if (njs_is_object(value)) {
+ proto = value->data.u.object->__proto__;
+
+ } else {
+ proto = &vm->prototypes[njs_primitive_prototype_index(value->type)];
+ }
- vm->retval.data.u.object = &vm->prototypes[index];
+ vm->retval.data.u.object = proto;
vm->retval.type = NJS_OBJECT;
vm->retval.data.truth = 1;
/* Fall through. */
case NJS_OBJECT:
+ case NJS_OBJECT_BOOLEAN:
+ case NJS_OBJECT_NUMBER:
+ case NJS_OBJECT_STRING:
case NJS_FUNCTION:
case NJS_REGEXP:
obj = object->data.u.object;
{ nxt_string("false.__proto__ === Boolean.prototype"),
nxt_string("true") },
+ { nxt_string("var b = Boolean(1); b.__proto__ === Boolean.prototype"),
+ nxt_string("true") },
+
+ { nxt_string("var b = new Boolean(1); b.__proto__ === Boolean.prototype"),
+ nxt_string("true") },
+
{ nxt_string("Number()"),
nxt_string("0") },
{ nxt_string("0..__proto__ === Number.prototype"),
nxt_string("true") },
+ { nxt_string("var n = Number(1); n.__proto__ === Number.prototype"),
+ nxt_string("true") },
+
+ { nxt_string("var n = new Number(1); n.__proto__ === Number.prototype"),
+ nxt_string("true") },
+
{ nxt_string("String()"),
nxt_string("") },
{ nxt_string("'test'.__proto__ === String.prototype"),
nxt_string("true") },
+ { nxt_string("var s = String('abc'); s.__proto__ === String.prototype"),
+ nxt_string("true") },
+
+ { nxt_string("var s = new String('abc'); s.__proto__ === String.prototype"),
+ nxt_string("true") },
+
{ nxt_string("'test'.constructor === String"),
nxt_string("true") },