This closes #124 issue on Github.
njs_ret_t ret;
njs_value_t *val;
njs_array_t *array;
+ njs_object_t *proto;
- array = value->data.u.array;
+ proto = value->data.u.object;
+
+ do {
+ if (nxt_fast_path(proto->type == NJS_ARRAY)) {
+ break;
+ }
+
+ proto = proto->__proto__;
+ } while (proto != NULL);
+
+ array = (njs_array_t *) proto;
if (setval != NULL) {
if (!njs_is_number(setval)) {
njs_value_t *setval, njs_value_t *retval)
{
nxt_uint_t n;
+ njs_object_t *proto;
njs_function_t *function;
njs_function_lambda_t *lambda;
- function = value->data.u.function;
+ proto = value->data.u.object;
+
+ do {
+ if (nxt_fast_path(proto->type == NJS_FUNCTION)) {
+ break;
+ }
+
+ proto = proto->__proto__;
+ } while (proto != NULL);
+
+ function = (njs_function_t *) proto;
if (function->native) {
for (n = function->args_offset; n < NJS_ARGS_TYPES_MAX; n++) {
* NXT_ERROR exception has been thrown.
*
* TODO:
- * Object.create([1,2]).length
* Object.defineProperty([1,2], '1', {configurable:false})
*/
njs_string_instance_length(njs_vm_t *vm, njs_value_t *value,
njs_value_t *setval, njs_value_t *retval)
{
- size_t size;
- uintptr_t length;
+ size_t size;
+ uintptr_t length;
+ njs_object_t *proto;
+ njs_object_value_t *ov;
/*
* This getter can be called for string primitive, String object,
*/
length = 0;
- if (value->type == NJS_OBJECT_STRING) {
- value = &value->data.u.object_value->value;
+ if (nxt_slow_path(njs_is_object(value))) {
+ proto = value->data.u.object;
+
+ do {
+ if (nxt_fast_path(proto->type == NJS_OBJECT_STRING)) {
+ break;
+ }
+
+ proto = proto->__proto__;
+ } while (proto != NULL);
+
+ if (proto != NULL) {
+ ov = (njs_object_value_t *) proto;
+ value = &ov->value;
+ }
}
if (njs_is_string(value)) {
"1..isPrototypeOf(p)"),
nxt_string("false") },
+ { nxt_string("Object.create(new String('asdf')).length"),
+ nxt_string("4") },
+
+ { nxt_string("Object.create(Object('123')).length"),
+ nxt_string("3") },
+
+ { nxt_string("Object.create([1,2]).length"),
+ nxt_string("2") },
+
+ { nxt_string("Object.create(function(a,b,c){}).length"),
+ nxt_string("3") },
+
{ nxt_string("Object.getOwnPropertyDescriptor({a:1}, 'a').value"),
nxt_string("1") },