Skip to content

Commit

Permalink
Merge pull request web-platform-tests#155 from gsnedders/distinguish_…
Browse files Browse the repository at this point in the history
…types

Distinguish float/string types
  • Loading branch information
jdm committed Mar 29, 2016
2 parents eaa4c5f + 039b214 commit 7986f16
Showing 1 changed file with 36 additions and 3 deletions.
39 changes: 36 additions & 3 deletions idlharness.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,16 @@ function awaitNCallbacks(n, cb, ctx) {
};
}

var fround = (function(){
if (Math.fround) return Math.fround;

var arr = new Float32Array(1);
return function fround(n) {
arr[0] = n;
return arr[0];
};
})();

/// IdlArray ///
// Entry point
self.IdlArray = function()
Expand Down Expand Up @@ -457,19 +467,42 @@ IdlArray.prototype.assert_type_is = function(value, type)
return;

case "float":
case "double":
assert_equals(typeof value, "number");
assert_equals(value, fround(value), "float rounded to 32-bit float should be itself");
assert_not_equals(value, Infinity);
assert_not_equals(value, -Infinity);
assert_not_equals(value, NaN);
return;

case "DOMHighResTimeStamp":
case "double":
assert_equals(typeof value, "number");
assert_not_equals(value, Infinity);
assert_not_equals(value, -Infinity);
assert_not_equals(value, NaN);
return;

case "unrestricted float":
assert_equals(typeof value, "number");
assert_equals(value, fround(value), "unrestricted float rounded to 32-bit float should be itself");
return;

case "unrestricted double":
// TODO: distinguish these cases
assert_equals(typeof value, "number");
return;

case "DOMString":
assert_equals(typeof value, "string");
return;

case "ByteString":
assert_equals(typeof value, "string");
assert_regexp_match(value, /^[\x00-\x7F]*$/);
return;

case "USVString":
// TODO: https://github.com/w3c/testharness.js/issues/92
assert_equals(typeof value, "string");
assert_regexp_match(value, /^([\x00-\ud7ff\ue000-\uffff]|[\ud800-\udbff][\udc00-\udfff])*$/);
return;

case "object":
Expand Down

0 comments on commit 7986f16

Please sign in to comment.