From 5272c6be2e396d54927d0e57d0e7ce0c32d8962d Mon Sep 17 00:00:00 2001 From: Pawel Murias Date: Sun, 15 Feb 2015 17:57:03 +0100 Subject: [PATCH] Make nqp::istype work on nqp::null(). --- src/vm/js/nqp-runtime/core.js | 5 +++++ t/nqp/89-istype.t | 4 +++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/vm/js/nqp-runtime/core.js b/src/vm/js/nqp-runtime/core.js index 2ad42e9ab6..760c671234 100644 --- a/src/vm/js/nqp-runtime/core.js +++ b/src/vm/js/nqp-runtime/core.js @@ -256,6 +256,11 @@ op.findmethod = function(obj, method) { }; op.istype = function(obj, type) { + /* Null always type checks false. */ + if (obj === null) { + return 0; + } + // TODO cases where the type_check_cache isn't authoritative var cache = obj._STable.type_check_cache; for (var i=0; i < cache.length; i++) { diff --git a/t/nqp/89-istype.t b/t/nqp/89-istype.t index c7df343406..903c8492d1 100644 --- a/t/nqp/89-istype.t +++ b/t/nqp/89-istype.t @@ -1,6 +1,6 @@ #! nqp -plan(7); +plan(8); class Foo {} @@ -19,3 +19,5 @@ ok(!nqp::istype(Foo, Bar), 'istype with two types, -'); ok(nqp::istype($sub, Foo), 'istype with subclass, +'); ok(!nqp::istype($foo, FooSub), 'istype with subclass, -'); ok(nqp::istype(FooSub, Foo), 'istype with subclass type, +'); + +ok(!nqp::istype(nqp::null(), Foo), 'istype on nqp::null()')