Skip to content

Commit

Permalink
[js] If the type cache is missing call type_check.
Browse files Browse the repository at this point in the history
  • Loading branch information
pmurias committed May 2, 2016
1 parent 38f2cea commit 04df939
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/vm/js/Operations.nqp
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,7 @@ class QAST::OperationsJS {
add_simple_op('findmethod', $T_OBJ, [$T_OBJ, $T_STR], :sideffects);
add_simple_op('can', $T_INT, [$T_OBJ, $T_STR], :sideffects);

add_simple_op('istype', $T_INT, [$T_OBJ, $T_OBJ], :sideffects);
add_simple_op('istype', $T_INT, [$T_OBJ, $T_OBJ], :sideffects, :ctx);

add_simple_op('split', $T_OBJ, [$T_STR, $T_STR], sub ($separator, $string) {
"new nqp.NQPArray({$string} == '' ? [] : {$string}.split({$separator}))"
Expand Down
17 changes: 13 additions & 4 deletions src/vm/js/nqp-runtime/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ var NQPArray = require('./array.js');

var bootstrap = require('./bootstrap.js');

var nqp = require('nqp-runtime');

exports.CodeRef = CodeRef;

op.atpos = function(array, index) {
Expand Down Expand Up @@ -292,7 +294,7 @@ op.findmethod = function(obj, method) {
return obj._STable.methodCache[method];
};

op.istype = function(obj, type) {
op.istype = function(ctx, obj, type) {
/* Null always type checks false. */
/* HACK - undefined */
if (obj === null || obj === undefined) {
Expand All @@ -315,10 +317,17 @@ op.istype = function(obj, type) {

// TODO cases where the typeCheckCache isn't authoritative
var cache = obj._STable.typeCheckCache;
for (var i = 0; i < cache.length; i++) {
if (cache[i] === type) {
return 1;
if (cache) {
for (var i = 0; i < cache.length; i++) {
if (cache[i] === type) {
return 1;
}
}
} else {
/* If we get here, need to call .^type_check on the value we're
* checking. */

return nqp.toBool(obj._STable.HOW.type_check(ctx, null, obj, type));
}
return 0;
};
Expand Down
5 changes: 4 additions & 1 deletion src/vm/js/nqp-runtime/deserialization.js
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,10 @@ BinaryCursor.prototype.STable = function(STable) {
for (var i = 0; i < typeCheckCacheLen; i++) {
typeCheckCache.push(this.variant());
}
STable.typeCheckCache = typeCheckCache;

if (typeCheckCache.length != 0) {
STable.typeCheckCache = typeCheckCache;
}

STable.modeFlags = this.U8();

Expand Down

0 comments on commit 04df939

Please sign in to comment.