}
+/*
+ * The __proto__ property of booleans, numbers and strings primitives
+ * and Boolean.prototype, Number.prototype, and String.prototype objects.
+ */
+
+njs_ret_t
+njs_primitive_prototype_get_proto(njs_vm_t *vm, njs_value_t *value)
+{
+ vm->retval.type = NJS_OBJECT;
+ vm->retval.data.truth = 1;
+
+ /*
+ * The __proto__ getters reside in object prototypes of primitive
+ * types. "AND 0x7" maps type of value to prototype offset:
+ * NJS_BOOLEAN > NJS_PROTOTYPE_BOOLEAN,
+ * NJS_NUMBER > NJS_PROTOTYPE_NUMBER,
+ * NJS_STRING > NJS_PROTOTYPE_STRING,
+ * NJS_OBJECT > NJS_PROTOTYPE_OBJECT.
+ * So "".__proto__ points to String.prototype while
+ * String.prototype.__proto__ points to Object.prototype.
+ */
+ vm->retval.data.u.object = &vm->prototypes[value->type & 7];
+
+ return NXT_OK;
+}
+
+
/*
* The "prototype" property of Object(), Array() and other functions is
* created on demand in the functions' private hash by the "prototype"
}
-static njs_ret_t
-njs_string_prototype_get_prototype(njs_vm_t *vm, njs_value_t *value)
-{
- vm->retval.type = NJS_OBJECT;
- vm->retval.data.truth = 1;
- vm->retval.data.u.object = &vm->prototypes[NJS_PROTOTYPE_STRING];
-
- return NXT_OK;
-}
-
-
static njs_ret_t
njs_string_prototype_length(njs_vm_t *vm, njs_value_t *value)
{
static const njs_object_prop_t njs_string_prototype_properties[] =
{
- { njs_getter(njs_string_prototype_get_prototype),
+ { njs_getter(njs_primitive_prototype_get_proto),
njs_string("__proto__"),
NJS_NATIVE_GETTER, 0, 0, 0, },
{ nxt_string("var o = { valueOf: function() { return 'OK' } } o.valueOf()"),
nxt_string("OK") },
+ { nxt_string("0..__proto__ === 1..__proto__"),
+ nxt_string("true") },
+
{ nxt_string("[].__proto__ === [1,2].__proto__"),
nxt_string("true") },
{ nxt_string("Object.name"),
nxt_string("Object") },
+ { nxt_string("Object.length"),
+ nxt_string("1") },
+
+ { nxt_string("Object.__proto__ === Function.prototype"),
+ nxt_string("true") },
+
{ nxt_string("Object.prototype.constructor === Object"),
nxt_string("true") },
+ { nxt_string("Object.prototype.__proto__ === null"),
+ nxt_string("true") },
+
{ nxt_string("Object.constructor === Function"),
nxt_string("true") },
+ { nxt_string("({}).__proto__ === Object.prototype"),
+ nxt_string("true") },
+
+ { nxt_string("({}).__proto__.constructor === Object"),
+ nxt_string("true") },
+
+ { nxt_string("({}).constructor === Object"),
+ nxt_string("true") },
+
{ nxt_string("var a = Array(3); a +''"),
nxt_string(",,") },
{ nxt_string("Array.length"),
nxt_string("1") },
+ { nxt_string("Array.__proto__ === Function.prototype"),
+ nxt_string("true") },
+
{ nxt_string("Array.prototype.constructor === Array"),
nxt_string("true") },
+ { nxt_string("Array.prototype.__proto__ === Object.prototype"),
+ nxt_string("true") },
+
{ nxt_string("Array.constructor === Function"),
nxt_string("true") },
{ nxt_string("Number.length"),
nxt_string("1") },
+ { nxt_string("Number.__proto__ === Function.prototype"),
+ nxt_string("true") },
+
{ nxt_string("Number.prototype.constructor === Number"),
nxt_string("true") },
+ { nxt_string("Number.prototype.__proto__ === Object.prototype"),
+ nxt_string("true") },
+
{ nxt_string("Number.constructor === Function"),
nxt_string("true") },
+ { nxt_string("0..__proto__ === Number.prototype"),
+ nxt_string("true") },
+
{ nxt_string("String()"),
nxt_string("") },
{ nxt_string("String.length"),
nxt_string("1") },
+ { nxt_string("String.__proto__ === Function.prototype"),
+ nxt_string("true") },
+
{ nxt_string("String.prototype.length"),
nxt_string("0") },
{ nxt_string("String.prototype.constructor === String"),
nxt_string("true") },
+ { nxt_string("String.prototype.__proto__ === Object.prototype"),
+ nxt_string("true") },
+
+ { nxt_string("''.__proto__ === String.prototype"),
+ nxt_string("true") },
+
{ nxt_string("String.constructor === Function"),
nxt_string("true") },
{ nxt_string("Function.length"),
nxt_string("1") },
+ { nxt_string("Function.__proto__ === Function.prototype"),
+ nxt_string("true") },
+
{ nxt_string("Function.prototype.constructor === Function"),
nxt_string("true") },
+ { nxt_string("Function.prototype.__proto__ === Object.prototype"),
+ nxt_string("true") },
+
{ nxt_string("Function.constructor === Function"),
nxt_string("true") },
{ nxt_string("RegExp.length"),
nxt_string("2") },
+ { nxt_string("RegExp.__proto__ === Function.prototype"),
+ nxt_string("true") },
+
{ nxt_string("RegExp.prototype.constructor === RegExp"),
nxt_string("true") },
+ { nxt_string("RegExp.prototype.__proto__ === Object.prototype"),
+ nxt_string("true") },
+
{ nxt_string("RegExp.constructor === Function"),
nxt_string("true") },