Skip to content
This repository has been archived by the owner on Apr 27, 2021. It is now read-only.

Commit

Permalink
added tests for typedarrays, per #3, and cached results include and v…
Browse files Browse the repository at this point in the history
…alidate against 'version'
  • Loading branch information
getify committed May 8, 2015
1 parent 14147bc commit 18d9d89
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
5 changes: 3 additions & 2 deletions lib/featuretests.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!DOCTYPE html><html><head><meta charset="utf-8"></head><body><script>

/*! es-feature-tests
v0.0.3-a (c) Kyle Simpson
v0.0.4-a (c) Kyle Simpson
MIT License: http://getify.mit-license.org
*/

Expand All @@ -22,7 +22,7 @@
try {
tmp = JSON.parse(tmp);
tmp.expires = tmp.expires || (now + expiration);
if (now < tmp.expires) {
if (now < tmp.expires && tmp.version && tmp.version == version) {
// send cached results
msg.res = tmp.results;
msg.expires = tmp.expires;
Expand Down Expand Up @@ -58,6 +58,7 @@
try {
localStorage.setItem(origin,JSON.stringify({
expires: now + expiration,
version: version,
results: JSON.parse(evt.data).res
}));
}
Expand Down
10 changes: 8 additions & 2 deletions lib/featuretests.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*! es-feature-tests
v0.0.3-a (c) Kyle Simpson
v0.0.4-a (c) Kyle Simpson
MIT License: http://getify.mit-license.org
*/

Expand Down Expand Up @@ -28,7 +28,7 @@ function runIt(code) {
computedProperty: { passes: "'use strict'; var a = 1, b = { ['x'+a]: 2 };" },
moduleExport: { passes: "'use strict'; export var a = 1;" },
moduleImport: { passes: "'use strict'; import {a} from 'b';" },
"class": { passes: "'use strict'; class Foo {}; class Bar extends Foo {};" },
classes: { passes: "'use strict'; class Foo {}; class Bar extends Foo {};" },
numericLiteral: { passes: "'use strict'; var a = 0o1, b = 0b10;" },
oldOctalLiteral: { fails: "'use strict'; var a = 01;" },
symbol: { passes: "'use strict'; var a = Symbol('b');" },
Expand All @@ -39,6 +39,9 @@ function runIt(code) {
};

assign(es6,{
// aliases
"class": es6.classes,

// semantics
letTDZ: { dependencies: ["letConst"], fails: "'use strict'; a = 1; let a;" },
constRedef: { dependencies: ["letConst"], fails: "'use strict'; const a = 1; a = 2;" },
Expand All @@ -53,6 +56,9 @@ function runIt(code) {
ObjectStatics: { is: "'use strict'; return ('getOwnSymbolNames' in Object) && ('assign' in Object) && ('is' in Object);" },
ArrayStatics: { is: "'use strict'; return ('from' in Array) && ('of' in Array);" },
ArrayMethods: { is: "'use strict'; return ('fill' in Array.prototype) && ('find' in Array.prototype) && ('findIndex' in Array.prototype) && ('entries' in Array.prototype) && ('keys' in Array.prototype) && ('values' in Array.prototype);" },
TypedArrays: { is: "'use strict'; return ('ArrayBuffer' in global) && ('Int8Array' in global) && ('Uint8Array' in global) && ('Int32Array' in global) && ('Float64Array' in global);" },
TypedArrayStatics: { dependencies: ["TypedArrays"], is: "use strict'; return ('from' in Uint32Array) && ('of' in Uint32Array);" },
TypedArrayMethods: { dependencies: ["TypedArrays"], is: "'use strict'; var x = new Int8Array(1); return ('slice' in x) && ('join' in x) && ('map' in x) && ('forEach' in x);" },
StringMethods: { is: "'use strict'; return ('includes' in String.prototype) && ('repeat' in String.prototype);" },
NumberStatics: { is: "'use strict'; return ('isNaN' in Number) && ('isInteger' in Number);" },
MathStatics: { is: "'use strict'; return ('hypot' in Math) && ('acosh' in Math) && ('imul' in Math);" },
Expand Down
7 changes: 4 additions & 3 deletions lib/rs.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*! es-feature-tests
v0.0.3-a (c) Kyle Simpson
v0.0.4-a (c) Kyle Simpson
MIT License: http://getify.mit-license.org
*/

Expand Down Expand Up @@ -31,6 +31,7 @@
try {
localStorage.setItem(origin,JSON.stringify({
expires: msg.expires || (now + expiration),
version: version,
results: msg.res
}));
}
Expand Down Expand Up @@ -89,7 +90,7 @@
try {
tmp = JSON.parse(tmp);
tmp.expires = tmp.expires || (now + expiration);
if (now < tmp.expires) {
if (now < tmp.expires && tmp.version && tmp.version == version) {
// send cached results
setTimeout(function timer(){
cb(tmp.results,(tmp.expires - expiration));
Expand Down Expand Up @@ -150,7 +151,7 @@
send_queue = [], receive_queue = [],
use_local_cache, iframe,
origin = "https://featuretests.io",
version = 1003, requests = {},
version = 1004, requests = {},
local_storage_available,
expiration = 14 * 1000 * 60 * 60 * 24;

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "es-feature-tests",
"version": "0.0.3-a",
"version": "0.0.4-a",
"description": "es-feature-tests: Feature Tests for JavaScript",
"main": "./lib/rs.js",
"scripts": {
Expand Down

0 comments on commit 18d9d89

Please sign in to comment.