├── .gitignore ├── .travis.yml ├── LICENSE ├── README.md ├── binding.gyp ├── index.js ├── package.json ├── src └── binding.cc └── test ├── sample.wasm ├── sample.wast └── test.js /.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | .nyc_output 3 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | env: 3 | - CXX="g++-4.8" 4 | node_js: 5 | - "4" 6 | - "5" 7 | - "6" 8 | - "7" 9 | sudo: false 10 | addons: 11 | apt: 12 | sources: 13 | - ubuntu-toolchain-r-test 14 | packages: 15 | - g++-4.8 16 | - gcc-4.8 17 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Evan Lucas 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # v8is 2 | 3 | [![Build Status](https://travis-ci.org/evanlucas/v8is.svg)](https://travis-ci.org/evanlucas/v8is) 4 | [![Coverage Status](https://coveralls.io/repos/evanlucas/v8is/badge.svg?branch=master&service=github)](https://coveralls.io/github/evanlucas/v8is?branch=master) 5 | 6 | Type checking on all sorts of values/objects 7 | 8 | *Note: `v8is` is only supported on Node.js v4+.* 9 | 10 | 11 | ## Install 12 | 13 | ```bash 14 | $ npm install v8is 15 | ``` 16 | 17 | ## Test 18 | 19 | ```bash 20 | $ npm test 21 | ``` 22 | 23 | ## API 24 | 25 | require it using: 26 | 27 | ```js 28 | const v8is = require('v8is') 29 | ``` 30 | 31 | The following functions are available: 32 | 33 | **NOTE: each function requires 1 argument. An error will be thrown otherwise** 34 | 35 | ### `isUndefined(arg)` 36 | 37 | ```js 38 | v8is.isUndefined(undefined) // => true 39 | v8is.isUndefined(null) // => false 40 | ``` 41 | 42 | ### `isNull(arg)` 43 | 44 | ```js 45 | v8is.isNull(null) // => true 46 | v8is.isNull(undefined) // => false 47 | ``` 48 | 49 | ### `isTrue(arg)` 50 | 51 | ```js 52 | v8is.isTrue(true) // => true 53 | v8is.isTrue(false) // => false 54 | ``` 55 | 56 | ### `isFalse(arg)` 57 | 58 | ### `isString(arg)` 59 | 60 | ### `isSymbol(arg)` 61 | 62 | ### `isFunction(arg)` 63 | 64 | ### `isArray(arg)` 65 | 66 | ### `isObject(arg)` 67 | 68 | ### `isBoolean(arg)` 69 | 70 | ### `isNumber(arg)` 71 | 72 | ### `isInt32(arg)` 73 | 74 | ### `isUint32(arg)` 75 | 76 | ### `isDate(arg)` 77 | 78 | ### `isArgumentsObject(arg)` 79 | 80 | ### `isBooleanObject(arg)` 81 | 82 | ### `isNumberObject(arg)` 83 | 84 | ### `isStringObject(arg)` 85 | 86 | ### `isError(arg)` 87 | 88 | Alias to `isNativeError` 89 | 90 | ### `isRegExp(arg)` 91 | 92 | ### `isGeneratorFunction(arg)` 93 | 94 | ### `isGeneratorObject(arg)` 95 | 96 | ### `isPromise(arg)` 97 | 98 | only works for native promises 99 | 100 | ### `isMap(arg)` 101 | 102 | ### `isSet(arg)` 103 | 104 | ### `isMapIterator(arg)` 105 | 106 | ### `isSetIterator(arg)` 107 | 108 | ### `isWeakMap(arg)` 109 | 110 | ### `isWeakSet(arg)` 111 | 112 | ### `isArrayBuffer(arg)` 113 | 114 | ### `isArrayBufferView(arg)` 115 | 116 | ### `isTypedArray(arg)` 117 | 118 | ### `isUint8Array(arg)` 119 | 120 | ### `isUint8ClampedArray(arg)` 121 | 122 | ### `isInt8Array(arg)` 123 | 124 | ### `isUint16Array(arg)` 125 | 126 | ### `isInt16Array(arg)` 127 | 128 | ### `isUint32Array(arg)` 129 | 130 | ### `isInt32Array(arg)` 131 | 132 | ### `isFloat32Array(arg)` 133 | 134 | ### `isFloat64Array(arg)` 135 | 136 | ### `isDataView(arg)` 137 | 138 | ### `isSharedArrayBuffer(arg)` 139 | 140 | ### `isProxy(arg)` 141 | 142 | Only supported on Node.js v6+. One should check before trying to use this. 143 | 144 | ```js 145 | 'use strict' 146 | 147 | const is = require('v8is') 148 | if (is.isProxy) { 149 | // ... 150 | } 151 | ``` 152 | 153 | ### `isWebAssemblyCompiledModule(arg)` 154 | 155 | Only supported on Node.js v7.0+. One should check before trying to use this. 156 | 157 | ### `isAsyncFunction(arg)` 158 | 159 | Only supported on Node.js v7.6+. One should check before trying to use this. 160 | 161 | ## Author 162 | 163 | Evan Lucas 164 | 165 | ## License 166 | 167 | MIT (See `LICENSE` for more info) 168 | -------------------------------------------------------------------------------- /binding.gyp: -------------------------------------------------------------------------------- 1 | { 2 | "targets": [{ 3 | "target_name": "v8is", 4 | "include_dirs": [ 5 | "", 19 | "repository": { 20 | "type": "git", 21 | "url": "https://github.com/evanlucas/v8is" 22 | }, 23 | "homepage": "https://github.com/evanlucas/v8is", 24 | "bugs": { 25 | "url": "https://github.com/evanlucas/v8is/issues" 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/binding.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using v8::String; 6 | using v8::FunctionTemplate; 7 | using v8::Value; 8 | using v8::Local; 9 | using Nan::GetFunction; 10 | using Nan::New; 11 | using Nan::Set; 12 | 13 | #define CHECK(obj) assert(obj) 14 | #define CHECK_EQ(a, b) CHECK((a) == (b)) 15 | #define METHOD(Name, arg) \ 16 | NAN_METHOD(Name) { \ 17 | CHECK_EQ(info.Length(), 1); \ 18 | info.GetReturnValue().Set(info[0]->arg()); \ 19 | } \ 20 | 21 | #define METHOD_NAMES(V) \ 22 | V(IsUndefined, isUndefined) \ 23 | V(IsNull, isNull) \ 24 | V(IsTrue, isTrue) \ 25 | V(IsFalse, isFalse) \ 26 | V(IsString, isString) \ 27 | V(IsSymbol, isSymbol) \ 28 | V(IsFunction, isFunction) \ 29 | V(IsArray, isArray) \ 30 | V(IsObject, isObject) \ 31 | V(IsBoolean, isBoolean) \ 32 | V(IsNumber, isNumber) \ 33 | V(IsInt32, isInt32) \ 34 | V(IsUint32, isUint32) \ 35 | V(IsDate, isDate) \ 36 | V(IsArgumentsObject, isArgumentsObject) \ 37 | V(IsBooleanObject, isBooleanObject) \ 38 | V(IsNumberObject, isNumberObject) \ 39 | V(IsStringObject, isStringObject) \ 40 | V(IsNativeError, isNativeError) \ 41 | V(IsRegExp, isRegExp) \ 42 | V(IsGeneratorFunction, isGeneratorFunction) \ 43 | V(IsGeneratorObject, isGeneratorObject) \ 44 | V(IsPromise, isPromise) \ 45 | V(IsMap, isMap) \ 46 | V(IsSet, isSet) \ 47 | V(IsMapIterator, isMapIterator) \ 48 | V(IsSetIterator, isSetIterator) \ 49 | V(IsWeakMap, isWeakMap) \ 50 | V(IsWeakSet, isWeakSet) \ 51 | V(IsArrayBuffer, isArrayBuffer) \ 52 | V(IsArrayBufferView, isArrayBufferView) \ 53 | V(IsTypedArray, isTypedArray) \ 54 | V(IsUint8Array, isUint8Array) \ 55 | V(IsUint8ClampedArray, isUint8ClampedArray) \ 56 | V(IsInt8Array, isInt8Array) \ 57 | V(IsUint16Array, isUint16Array) \ 58 | V(IsInt16Array, isInt16Array) \ 59 | V(IsUint32Array, isUint32Array) \ 60 | V(IsInt32Array, isInt32Array) \ 61 | V(IsFloat32Array, isFloat32Array) \ 62 | V(IsFloat64Array, isFloat64Array) \ 63 | V(IsDataView, isDataView) \ 64 | V(IsSharedArrayBuffer, isSharedArrayBuffer) 65 | 66 | #define V8_4_9_METHOD_NAMES(V) \ 67 | V(IsProxy, isProxy) 68 | 69 | #define V8_5_4_METHOD_NAMES(V) \ 70 | V(IsWebAssemblyCompiledModule, isWebAssemblyCompiledModule) 71 | 72 | #define V8_5_5_METHOD_NAMES(V) \ 73 | V(IsAsyncFunction, isAsyncFunction) 74 | 75 | #define V(Name, S) METHOD(S, Name) 76 | METHOD_NAMES(V) 77 | #if V8_MAJOR_VERSION == 4 && V8_MINOR_VERSION >= 9 || V8_MAJOR_VERSION > 4 78 | V8_4_9_METHOD_NAMES(V) 79 | #endif 80 | #if V8_MAJOR_VERSION == 5 && V8_MINOR_VERSION >= 4 || V8_MAJOR_VERSION > 5 81 | V8_5_4_METHOD_NAMES(V) 82 | #endif 83 | #if V8_MAJOR_VERSION == 5 && V8_MINOR_VERSION >= 5 || V8_MAJOR_VERSION > 5 84 | V8_5_5_METHOD_NAMES(V) 85 | #endif 86 | #undef V 87 | 88 | #define DECLARE(Name, S) \ 89 | Set(target, New(# S).ToLocalChecked(), \ 90 | GetFunction(New(S)).ToLocalChecked()); 91 | 92 | NAN_MODULE_INIT(Init) { 93 | #define V(Name, S) DECLARE(Name, S) 94 | METHOD_NAMES(V) 95 | #if V8_MAJOR_VERSION == 4 && V8_MINOR_VERSION >= 9 || V8_MAJOR_VERSION > 4 96 | V8_4_9_METHOD_NAMES(V) 97 | #endif 98 | #if V8_MAJOR_VERSION == 5 && V8_MINOR_VERSION >= 4 || V8_MAJOR_VERSION > 5 99 | V8_5_4_METHOD_NAMES(V) 100 | #endif 101 | #if V8_MAJOR_VERSION == 5 && V8_MINOR_VERSION >= 5 || V8_MAJOR_VERSION > 5 102 | V8_5_5_METHOD_NAMES(V) 103 | #endif 104 | #undef V 105 | } 106 | 107 | NODE_MODULE(v8is, Init) 108 | -------------------------------------------------------------------------------- /test/sample.wasm: -------------------------------------------------------------------------------- 1 | asm`a 2 | A* -------------------------------------------------------------------------------- /test/sample.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (func $a (result i32) 3 | i32.const 42) 4 | (export "a" (func $a))) 5 | -------------------------------------------------------------------------------- /test/test.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | const fs = require('fs') 4 | const test = require('tap').test 5 | const v8is = require('../') 6 | const keys = Object.keys(v8is) 7 | 8 | function getFunctions() { 9 | const out = keys.slice() 10 | const len = arguments.length 11 | if (!len) return out 12 | for (let i = 0; i < len; i++) { 13 | var arg = arguments[i] 14 | var idx = out.indexOf(arg) 15 | if (~idx) { 16 | out.splice(idx, 1) 17 | } 18 | } 19 | 20 | return out 21 | } 22 | 23 | test('isUndefined', function(t) { 24 | t.strictEqual(v8is.isUndefined(undefined), true) 25 | t.strictEqual(v8is.isUndefined(null), false) 26 | t.strictEqual(v8is.isUndefined(0), false) 27 | t.strictEqual(v8is.isUndefined(''), false) 28 | t.end() 29 | }) 30 | 31 | test('isNull', function(t) { 32 | t.strictEqual(v8is.isNull(null), true) 33 | t.strictEqual(v8is.isNull(undefined), false) 34 | t.strictEqual(v8is.isNull(0), false) 35 | t.strictEqual(v8is.isNull(false), false) 36 | t.end() 37 | }) 38 | 39 | test('isTrue', function(t) { 40 | t.strictEqual(v8is.isTrue(true), true) 41 | t.strictEqual(v8is.isTrue(false), false) 42 | t.strictEqual(v8is.isTrue(''), false) 43 | t.end() 44 | }) 45 | 46 | test('isFalse', function(t) { 47 | t.strictEqual(v8is.isFalse(false), true) 48 | t.strictEqual(v8is.isFalse(true), false) 49 | t.strictEqual(v8is.isFalse(''), false) 50 | t.end() 51 | }) 52 | 53 | test('isString', function(t) { 54 | t.strictEqual(v8is.isString(''), true) 55 | t.strictEqual(v8is.isString(1), false) 56 | t.strictEqual(v8is.isString(new String('1')), false) 57 | t.end() 58 | }) 59 | 60 | test('isSymbol', function(t) { 61 | t.strictEqual(v8is.isSymbol(Symbol('123')), true) 62 | t.strictEqual(v8is.isSymbol('123'), false) 63 | t.end() 64 | }) 65 | 66 | test('isFunction', function(t) { 67 | t.strictEqual(v8is.isFunction(function() {}), true) 68 | t.strictEqual(v8is.isFunction({}), false) 69 | t.end() 70 | }) 71 | 72 | test('isArray', function(t) { 73 | t.strictEqual(v8is.isArray([]), true) 74 | t.strictEqual(v8is.isArray(new Array(0)), true) 75 | t.strictEqual(v8is.isArray({}), false) 76 | t.end() 77 | }) 78 | 79 | test('isObject', function(t) { 80 | t.strictEqual(v8is.isObject(''), false) 81 | t.strictEqual(v8is.isObject(1), false) 82 | t.strictEqual(v8is.isObject({}), true) 83 | t.strictEqual(v8is.isObject(function() {}), true) 84 | t.end() 85 | }) 86 | 87 | test('isBoolean', function(t) { 88 | t.strictEqual(v8is.isBoolean(true), true) 89 | t.strictEqual(v8is.isBoolean(false), true) 90 | t.strictEqual(v8is.isBoolean(1), false) 91 | t.strictEqual(v8is.isBoolean('true'), false) 92 | t.end() 93 | }) 94 | 95 | test('isNumber', function(t) { 96 | t.strictEqual(v8is.isNumber(1), true) 97 | t.strictEqual(v8is.isNumber('1'), false) 98 | t.strictEqual(v8is.isNumber(true), false) 99 | t.end() 100 | }) 101 | 102 | test('isInt32', function(t) { 103 | t.strictEqual(v8is.isInt32(1), true) 104 | t.strictEqual(v8is.isInt32(-1), true) 105 | t.strictEqual(v8is.isInt32('1'), false) 106 | t.end() 107 | }) 108 | 109 | test('isUint32', function(t) { 110 | t.strictEqual(v8is.isUint32(1), true) 111 | t.strictEqual(v8is.isUint32(-1), false) 112 | t.strictEqual(v8is.isUint32('1'), false) 113 | t.end() 114 | }) 115 | 116 | test('isDate', function(t) { 117 | t.strictEqual(v8is.isDate(new Date()), true) 118 | t.strictEqual(v8is.isDate(Date.now()), false) 119 | t.end() 120 | }) 121 | 122 | test('isArgumentsObject', function(t) { 123 | ;(function() { 124 | t.strictEqual(v8is.isArgumentsObject(arguments), true) 125 | })() 126 | t.strictEqual(v8is.isArgumentsObject([]), false) 127 | t.end() 128 | }) 129 | 130 | test('isBooleanObject', function(t) { 131 | t.strictEqual(v8is.isBooleanObject(true), false) 132 | t.strictEqual(v8is.isBooleanObject(false), false) 133 | t.strictEqual(v8is.isBooleanObject(new Boolean(true)), true) 134 | t.strictEqual(v8is.isBooleanObject(new Boolean(false)), true) 135 | t.strictEqual(v8is.isBooleanObject(new Boolean(0)), true) 136 | t.end() 137 | }) 138 | 139 | test('isNumberObject', function(t) { 140 | t.strictEqual(v8is.isNumberObject(new Number(1)), true) 141 | t.strictEqual(v8is.isNumberObject(1), false) 142 | t.end() 143 | }) 144 | 145 | test('isStringObject', function(t) { 146 | t.strictEqual(v8is.isStringObject(''), false) 147 | t.strictEqual(v8is.isStringObject(new String('')), true) 148 | t.end() 149 | }) 150 | 151 | test('isError', (t) => { 152 | t.equal(v8is.isError(new Error()), true) 153 | t.equal(v8is.isError(true), false) 154 | class E extends Error { 155 | constructor(m) { 156 | super(m) 157 | } 158 | } 159 | t.equal(v8is.isError(new E()), true) 160 | t.end() 161 | }) 162 | 163 | test('isRegExp', function(t) { 164 | t.strictEqual(v8is.isRegExp(/123/), true) 165 | t.strictEqual(v8is.isRegExp(new RegExp('123')), true) 166 | t.strictEqual(v8is.isRegExp('123'), false) 167 | t.end() 168 | }) 169 | 170 | test('isGeneratorFunction', function(t) { 171 | function *gen() {} 172 | t.strictEqual(v8is.isGeneratorFunction(gen), true) 173 | t.strictEqual(v8is.isGeneratorFunction(function() {}), false) 174 | t.end() 175 | }) 176 | 177 | test('isGeneratorObject', function(t) { 178 | function *gen() { 179 | yield 1 180 | yield 2 181 | } 182 | t.strictEqual(v8is.isGeneratorObject(gen()), true) 183 | t.strictEqual(v8is.isGeneratorObject(gen), false) 184 | t.end() 185 | }) 186 | 187 | test('isPromise', function(t) { 188 | var a = new Promise(function() {}, function() {}) 189 | t.strictEqual(v8is.isPromise(a), true) 190 | t.strictEqual(v8is.isPromise(true), false) 191 | t.end() 192 | }) 193 | 194 | test('isMap', function(t) { 195 | t.strictEqual(v8is.isMap(new Map()), true) 196 | t.strictEqual(v8is.isMap(new Set()), false) 197 | t.strictEqual(v8is.isMap(new Map().keys()), false) 198 | t.end() 199 | }) 200 | 201 | test('isSet', function(t) { 202 | t.strictEqual(v8is.isSet(new Set()), true) 203 | t.strictEqual(v8is.isSet(new Map()), false) 204 | t.strictEqual(v8is.isSet(new Set().entries()), false) 205 | t.end() 206 | }) 207 | 208 | test('isMapIterator', function(t) { 209 | t.strictEqual(v8is.isMapIterator(new Map().keys()), true) 210 | t.strictEqual(v8is.isMapIterator(new Map()), false) 211 | t.strictEqual(v8is.isMapIterator(new Set().keys()), false) 212 | t.end() 213 | }) 214 | 215 | test('isSetIterator', function(t) { 216 | t.strictEqual(v8is.isSetIterator(new Set().keys()), true) 217 | t.strictEqual(v8is.isSetIterator(new Set()), false) 218 | t.strictEqual(v8is.isSetIterator(new Map().keys()), false) 219 | t.end() 220 | }) 221 | 222 | test('isWeakMap', function(t) { 223 | t.strictEqual(v8is.isWeakMap(new Map()), false) 224 | t.strictEqual(v8is.isWeakMap(new WeakMap()), true) 225 | t.end() 226 | }) 227 | 228 | test('isWeakSet', function(t) { 229 | t.strictEqual(v8is.isWeakSet(new Set()), false) 230 | t.strictEqual(v8is.isWeakSet(new WeakSet()), true) 231 | t.end() 232 | }) 233 | 234 | test('isArrayBuffer', function(t) { 235 | t.strictEqual(v8is.isArrayBuffer(new ArrayBuffer([])), true) 236 | t.strictEqual(v8is.isArrayBuffer([]), false) 237 | t.end() 238 | }) 239 | 240 | test('isArrayBufferView', function(t) { 241 | t.strictEqual(v8is.isArrayBufferView(new Uint8Array([])), true) 242 | t.strictEqual(v8is.isArrayBufferView([]), false) 243 | t.end() 244 | }) 245 | 246 | test('isTypedArray', function(t) { 247 | t.strictEqual(v8is.isTypedArray(new Uint8Array([])), true) 248 | t.strictEqual(v8is.isTypedArray([]), false) 249 | t.strictEqual(v8is.isTypedArray(new Buffer(0)), true) 250 | t.end() 251 | }) 252 | 253 | test('isUint8Array', function(t) { 254 | t.strictEqual(v8is.isUint8Array(new Uint8Array([])), true) 255 | t.strictEqual(v8is.isUint8Array([]), false) 256 | t.strictEqual(v8is.isUint8Array(new Buffer(0)), true) 257 | t.end() 258 | }) 259 | 260 | test('isUint8ClampedArray', function(t) { 261 | t.strictEqual(v8is.isUint8ClampedArray(new Uint8ClampedArray([1])), true) 262 | t.strictEqual(v8is.isUint8ClampedArray([]), false) 263 | t.end() 264 | }) 265 | 266 | test('isInt8Array', function(t) { 267 | t.strictEqual(v8is.isInt8Array(new Int8Array([])), true) 268 | t.strictEqual(v8is.isInt8Array(new Uint8Array([])), false) 269 | t.strictEqual(v8is.isInt8Array([]), false) 270 | t.end() 271 | }) 272 | 273 | test('isUint16Array', function(t) { 274 | t.strictEqual(v8is.isUint16Array(new Uint16Array([])), true) 275 | t.strictEqual(v8is.isUint16Array([]), false) 276 | t.end() 277 | }) 278 | 279 | test('isInt16Array', function(t) { 280 | t.strictEqual(v8is.isInt16Array(new Int16Array([])), true) 281 | t.strictEqual(v8is.isInt16Array(new Uint16Array([])), false) 282 | t.strictEqual(v8is.isInt16Array([]), false) 283 | t.end() 284 | }) 285 | 286 | test('isUint32Array', function(t) { 287 | t.strictEqual(v8is.isUint32Array(new Uint32Array([])), true) 288 | t.strictEqual(v8is.isUint32Array([]), false) 289 | t.end() 290 | }) 291 | 292 | test('isInt32Array', function(t) { 293 | t.strictEqual(v8is.isInt32Array(new Int32Array([])), true) 294 | t.strictEqual(v8is.isInt32Array(new Uint32Array([])), false) 295 | t.strictEqual(v8is.isInt32Array([]), false) 296 | t.end() 297 | }) 298 | 299 | test('isFloat32Array', function(t) { 300 | t.strictEqual(v8is.isFloat32Array(new Float32Array([])), true) 301 | t.strictEqual(v8is.isFloat32Array(new Uint32Array([])), false) 302 | t.strictEqual(v8is.isFloat32Array([]), false) 303 | t.end() 304 | }) 305 | 306 | test('isFloat64Array', function(t) { 307 | t.strictEqual(v8is.isFloat64Array(new Float64Array([])), true) 308 | t.strictEqual(v8is.isFloat64Array(new Uint32Array([])), false) 309 | t.strictEqual(v8is.isFloat64Array([]), false) 310 | t.end() 311 | }) 312 | 313 | test('isDataView', function(t) { 314 | t.strictEqual(v8is.isDataView(new DataView(new ArrayBuffer(0))), true) 315 | t.strictEqual(v8is.isDataView([]), false) 316 | t.end() 317 | }) 318 | 319 | if (v8is.isProxy) { 320 | test('isProxy', (t) => { 321 | t.equal(v8is.isProxy({}), false) 322 | const handler = {} 323 | const p = new Proxy({}, handler) 324 | t.equal(v8is.isProxy(p), true) 325 | t.end() 326 | }) 327 | } 328 | 329 | if (global.SharedArrayBuffer) { 330 | test('isSharedArrayBuffer', (t) => { 331 | t.strictEqual(v8is.isSharedArrayBuffer(new SharedArrayBuffer(0)), true) 332 | t.strictEqual(v8is.isSharedArrayBuffer([]), false) 333 | t.end() 334 | }) 335 | } 336 | 337 | if (v8is.isWebAssemblyCompiledModule) { 338 | test('isWebAssemblyCompiledModule', (t) => { 339 | t.strictEqual(v8is.isWebAssemblyCompiledModule({}), false) 340 | if (global.WebAssembly && WebAssembly.Module) { 341 | const buf = fs.readFileSync(__dirname + "/sample.wasm") 342 | let module = null 343 | try { 344 | module = new WebAssembly.Module(buf) 345 | } catch (err) { 346 | // Compilation may fail due to the unstable nature of WebAssembly 347 | // at this moment. 348 | } 349 | if (module !== null) { 350 | t.strictEqual(v8is.isWebAssemblyCompiledModule(module), true) 351 | } 352 | } 353 | t.end() 354 | }) 355 | } 356 | 357 | if (v8is.isAsyncFunction) { 358 | test('isAsyncFunction', (t) => { 359 | t.equal(v8is.isAsyncFunction(1), false) 360 | t.equal(v8is.isAsyncFunction({}), false) 361 | t.equal(v8is.isAsyncFunction(() => {}), false) 362 | 363 | let func = null 364 | try { 365 | func = eval("(async function() {})") 366 | } catch (err) {} 367 | if (func !== null) { 368 | t.equal(v8is.isAsyncFunction(func), true) 369 | } 370 | t.end() 371 | }) 372 | } 373 | 374 | test('required arguments', function(t) { 375 | const funcs = getFunctions() 376 | funcs.forEach(function(func) { 377 | t.throws(function() { 378 | v8is[func]() 379 | }, /argument is required/) 380 | }) 381 | t.end() 382 | }) 383 | --------------------------------------------------------------------------------