const njs_value_t *retval;
nxt_lvlhsh_query_t lhq;
- /* TODO: test constructor is function or native: TypeError. */
- /* TODO: test object is object: false. */
+ if (!njs_is_function(constructor) && !njs_is_native(constructor)) {
+ vm->exception = &njs_exception_type_error;
+ return NXT_ERROR;
+ }
retval = &njs_value_false;
- lhq.key_hash = NJS_PROTOTYPE_HASH;
- lhq.key.len = sizeof("prototype") - 1;
- lhq.key.data = (u_char *) "prototype";
+ if (njs_is_object(object)) {
- prop = njs_object_property(vm, constructor->data.u.object, &lhq);
+ lhq.key_hash = NJS_PROTOTYPE_HASH;
+ lhq.key.len = sizeof("prototype") - 1;
+ lhq.key.data = (u_char *) "prototype";
- if (prop != NULL) {
- value = &prop->value;
+ prop = njs_object_property(vm, constructor->data.u.object, &lhq);
- if (prop->type == NJS_NATIVE_GETTER) {
- /* STUB: getter should be called by some njs_object_property() */
- ret = prop->value.data.u.getter(vm, constructor);
+ if (prop != NULL) {
+ value = &prop->value;
- if (nxt_slow_path(ret != NXT_OK)) {
- return ret;
- }
+ if (prop->type == NJS_NATIVE_GETTER) {
+ /*
+ * STUB: getter should be called by some njs_object_property()
+ */
+ ret = prop->value.data.u.getter(vm, constructor);
- value = &vm->retval;
- }
+ if (nxt_slow_path(ret != NXT_OK)) {
+ return ret;
+ }
- /* TODO: test prop->value is object. */
+ value = &vm->retval;
+ }
- prototype = value->data.u.object;
- proto = object->data.u.object;
+ /* TODO: test prop->value is object. */
- do {
- proto = proto->__proto__;
+ prototype = value->data.u.object;
+ proto = object->data.u.object;
- if (proto == prototype) {
- retval = &njs_value_true;
- break;
- }
+ do {
+ proto = proto->__proto__;
- } while (proto != NULL);
+ if (proto == prototype) {
+ retval = &njs_value_true;
+ break;
+ }
+
+ } while (proto != NULL);
+ }
}
vm->retval = *retval;
{ nxt_string("/./.__proto__.test.call(/a{2}/, 'aaa')"),
nxt_string("true") },
+ { nxt_string("true instanceof Boolean"),
+ nxt_string("false") },
+
+ { nxt_string("1 instanceof Number"),
+ nxt_string("false") },
+
+ { nxt_string("'' instanceof String"),
+ nxt_string("false") },
+
{ nxt_string("({}) instanceof Object"),
nxt_string("true") },
+ { nxt_string("[] instanceof []"),
+ nxt_string("TypeError") },
+
{ nxt_string("[] instanceof Array"),
nxt_string("true") },
{ nxt_string("[] instanceof Object"),
nxt_string("true") },
+ { nxt_string("/./ instanceof RegExp"),
+ nxt_string("true") },
+
+ { nxt_string("/./ instanceof Object"),
+ nxt_string("true") },
+
{ nxt_string("var o = Object(); o"),
nxt_string("[object Object]") },