From 3dbdece962dc1e35f6fb4fe2ec4adf3024eee510 Mon Sep 17 00:00:00 2001 From: Matteo Collina Date: Mon, 5 Mar 2018 21:56:34 +0100 Subject: [PATCH] Back support for Node < 8. --- build/common-replacements.js | 59 ++++++ build/test-replacements.js | 152 ++++++++++++--- package.json | 2 + test/common/README.md | 24 ++- test/common/benchmark.js | 40 +++- test/common/countdown.js | 36 +++- test/common/dns.js | 38 +++- test/common/duplexpair.js | 36 +++- test/common/fixtures.js | 36 +++- test/common/index.js | 278 +++++++++++++++++---------- test/common/index.mjs | 24 ++- test/common/inspector-helper.js | 47 ++++- test/common/wpt.js | 36 +++- test/parallel/test-string-decoder.js | 3 - 14 files changed, 653 insertions(+), 158 deletions(-) create mode 100644 build/common-replacements.js diff --git a/build/common-replacements.js b/build/common-replacements.js new file mode 100644 index 0000000..e17f5d7 --- /dev/null +++ b/build/common-replacements.js @@ -0,0 +1,59 @@ +module.exports.altForEachImplReplacement = [ + /$/ + , '\nfunction forEach (xs, f) {\n' + + ' for (var i = 0, l = xs.length; i < l; i++) {\n' + + ' f(xs[i], i);\n' + + ' }\n' + + '}\n' +] + +module.exports.altForEachUseReplacement = [ + /(\W)([\w\.\(\),\[\] ']+)(\.forEach\()/gm + , '$1forEach($2, ' +] + +module.exports.specialForEachReplacment = [ + /(\W)(\[(?:\d\,\s)+\d\])(\.forEach\()/gm + , '$1forEach($2, ' +] + +module.exports.altIndexOfImplReplacement = [ + /$/ + , '\nfunction indexOf (xs, x) {\n' + + ' for (var i = 0, l = xs.length; i < l; i++) {\n' + + ' if (xs[i] === x) return i;\n' + + ' }\n' + + ' return -1;\n' + + '}\n' +] + +module.exports.altIndexOfUseReplacement = [ + /(\W)([\w\.\(\),\[\]]+)(\.indexOf\()/gm + , '$1indexOf($2, ' +] +module.exports.objectKeysDefine = [ + /^('use strict';)$/m + , '$1\n\n/**/\nvar objectKeys = Object.keys || function (obj) {\n' + + ' var keys = [];\n' + + ' for (var key in obj) keys.push(key);\n' + + ' return keys;\n' + + '}\n/**/\n' +] + +module.exports.objectKeysReplacement = [ + /Object\.keys/g + , 'objectKeys' + ] + + +module.exports.bufferShimFix = [ + /^('use strict';)$/m, + `/**/ + const bufferShim = require('safe-buffer').Buffer; + /**/` +] + +module.exports.bufferStaticMethods = [ + /Buffer\.((?:alloc)|(?:allocUnsafe)|(?:from))/g, + `bufferShim.$1` +] diff --git a/build/test-replacements.js b/build/test-replacements.js index 8f718cf..830dbca 100644 --- a/build/test-replacements.js +++ b/build/test-replacements.js @@ -1,3 +1,8 @@ +const altForEachImplReplacement = require('./common-replacements').altForEachImplReplacement + , altForEachUseReplacement = require('./common-replacements').altForEachUseReplacement + , objectKeysDefine = require('./common-replacements').objectKeysDefine + , objectKeysReplacement = require('./common-replacements').objectKeysReplacement + module.exports.all = [ [ /require\(['"]string_decoder['"]\)/g @@ -16,27 +21,57 @@ module.exports.all = [ ] -module.exports['common.js'] = [ + +module.exports['test-string-decoder.js'] = [ + // test removed because it is V8-version dependant. [ - /^ setImmediate,$/m - , ' typeof setImmediate == \'undefined\' ? null : setImmediate,' + /test\('utf-8', bufferShim\.from\('EDA0B5EDB08D'.*\n.*\n/ + , '' + ], + , [ + /test\('utf-8', bufferShim\.from\('F0B841', 'hex'.*\n/ + , '' ] - , [ - /^ clearImmediate,$/m - , ' typeof clearImmediate == \'undefined\' ? null : clearImmediate,' + /test\('utf-8', bufferShim\.from\('CCE2B8B8', 'hex'.*\n/ + , '' + ] + , [ + /test\('utf-8', bufferShim\.from\('E2B8CCB8', 'hex'.*\n/ + , '' ] - , [ - /^ global];$/m - , ' global].filter(Boolean);' + /assert\.strictEqual\(decoder\.end(), '\ufffd'\);\n/ + , '' ] +] + +module.exports['common.js'] = [ + objectKeysDefine + , objectKeysReplacement + , altForEachImplReplacement + , altForEachUseReplacement , [ - /^/ - , 'require(\'babel-polyfill\');' + /(exports.mustCall[\s\S]*)/m + , '$1\n' + + 'if (!util._errnoException) {\n' + + ' var uv;\n' + + ' util._errnoException = function(err, syscall) {\n' + + ' if (util.isUndefined(uv)) try { uv = process.binding(\'uv\'); } catch (e) {}\n' + + ' var errname = uv ? uv.errname(err) : \'\';\n' + + ' var e = new Error(syscall + \' \' + errname);\n' + + ' e.code = errname;\n' + + ' e.errno = errname;\n' + + ' e.syscall = syscall;\n' + + ' return e;\n' + + ' };\n' + + '}\n' ] + // for streams2 on node 0.11 + // and dtrace in 0.10 + // and coverage in all , [ /^( for \(var x in global\) \{|function leakedGlobals\(\) \{)$/m , ' /**/\n' @@ -51,26 +86,89 @@ module.exports['common.js'] = [ + '\'core,__core-js_shared__,Promise,Map,Set,WeakMap,WeakSet,Reflect,System,asap,Observable,regeneratorRuntime,_babelPolyfill\'.split(\',\').filter(function (item) { return typeof global[item] !== undefined}).forEach(function (item) {knownGlobals.push(global[item])})' + ' /**/\n\n$1' ] -] -module.exports['test-string-decoder.js'] = [ - // test removed because it is V8-version dependant. - [ - /test\('utf-8', bufferShim\.from\('EDA0B5EDB08D'.*\n.*\n/ - , '' - ], + // for node 0.8 , [ - /test\('utf-8', bufferShim\.from\('F0B841', 'hex'.*\n/ - , '' + /^/ + , '/**/' + + '\nif (!global.setImmediate) {\n' + + ' global.setImmediate = function setImmediate(fn) {\n' + + + ' return setTimeout(fn.bind.apply(fn, arguments), 4);\n' + + ' };\n' + + '}\n' + + 'if (!global.clearImmediate) {\n' + + ' global.clearImmediate = function clearImmediate(i) {\n' + + ' return clearTimeout(i);\n' + + ' };\n' + + '}\n' + + '/**/\n' ] , [ - /test\('utf-8', bufferShim\.from\('CCE2B8B8', 'hex'.*\n/ - , '' + /^if \(global\.ArrayBuffer\) \{([^\}]+)\}$/m + , '/**/if (!process.browser) {' + + '\nif \(global\.ArrayBuffer\) {$1}\n' + + '}/**/\n' ] - , [ - /test\('utf-8', bufferShim\.from\('E2B8CCB8', 'hex'.*\n/ - , '' + , [ + /^Object\.defineProperty\(([\w\W]+?)\}\)\;/mg + , '/**/if (!process.browser) {' + + '\nObject\.defineProperty($1});\n' + + '}/**/\n' + ] + , [ + /if \(!process\.send\)/ + , 'if (!process.send && !process.browser)' ] - , [ - /assert\.strictEqual\(decoder\.end(), '\ufffd'\);\n/ + , [ + /^/, + `/**/ + require('babel-polyfill'); + var util = require('util'); + for (var i in util) exports[i] = util[i]; + /**/` + ], + [ + /var regexp = `\^\(\\\\w\+\)\\\\s\+\\\\s\$\{port\}\/\$\{protocol\}\\\\s`;/, + `var regexp = '^(\\w+)\\s+\\s' + port + '/' + protocol + '\\s';` + ], + [ + /^var util = require\('util'\);/m + , '\n/**/\nvar util = require(\'core-util-is\');\n' + + 'util.inherits = require(\'inherits\');\n/**/\n' + ], + [ + /^const util = require\('util'\);/m +, '\n/**/\nvar util = require(\'core-util-is\');\n' + + 'util.inherits = require(\'inherits\');\n/**/\n' +] +, [ + /process\.binding\('timer_wrap'\)\.Timer;/, + '{now: function (){}}' +], +[ + /(exports\.enoughTestCpu[^;]+;)/, + '/*$1*/' +], +[ + /exports\.buildType/, + '//exports.buildType' +], +[ + /require\('async_hooks'\)/, + '/*require(\'async_hooks\')' +], +[ + /\}\).enable\(\);/, + '}).enable();*/' +], +[ + /(?:var|const) async_wrap = process\.binding\('async_wrap'\);\n.*(?:var|const) (?:{ )?kCheck(?: })? = async_wrap\.constants(?:\.kCheck)?;/gm, + '// const async_wrap = process.binding(\'async_wrap\');\n' + + ' // const kCheck = async_wrap.constants.kCheck;' +], +[ + /async_wrap\.async_hook_fields\[kCheck\] \+= 1;/, + '// async_wrap.async_hook_fields[kCheck] += 1;' +] ] diff --git a/package.json b/package.json index 13751d9..c359e28 100644 --- a/package.json +++ b/package.json @@ -8,6 +8,8 @@ }, "devDependencies": { "babel-polyfill": "^6.23.0", + "core-util-is": "^1.0.2", + "inherits": "^2.0.3", "tap": "~0.4.8" }, "scripts": { diff --git a/test/common/README.md b/test/common/README.md index bfcf032..0e25d98 100644 --- a/test/common/README.md +++ b/test/common/README.md @@ -1,4 +1,20 @@ -require('babel-polyfill');# Node.js Core Test Common Modules +/**/ + require('babel-polyfill'); + var util = require('util'); + for (var i in util) exports[i] = util[i]; + /**//**/ +if (!global.setImmediate) { + global.setImmediate = function setImmediate(fn) { + return setTimeout(fn.bind.apply(fn, arguments), 4); + }; +} +if (!global.clearImmediate) { + global.clearImmediate = function clearImmediate(i) { + return clearTimeout(i); + }; +} +/**/ +# Node.js Core Test Common Modules This directory contains modules used to test the Node.js implementation. @@ -517,3 +533,9 @@ implementation with tests from [`common.hijackStdErr()`]: #hijackstderrlistener [`common.hijackStdOut()`]: #hijackstdoutlistener [internationalization]: https://github.com/nodejs/node/wiki/Intl + +function forEach (xs, f) { + for (var i = 0, l = xs.length; i < l; i++) { + f(xs[i], i); + } +} diff --git a/test/common/benchmark.js b/test/common/benchmark.js index 2e45df7..555dc62 100644 --- a/test/common/benchmark.js +++ b/test/common/benchmark.js @@ -1,7 +1,33 @@ -require('babel-polyfill'); /* eslint-disable required-modules */ +/**/ +require('babel-polyfill'); +var util = require('util'); +for (var i in util) { + exports[i] = util[i]; +} /**/ /**/ +if (!global.setImmediate) { + global.setImmediate = function setImmediate(fn) { + return setTimeout(fn.bind.apply(fn, arguments), 4); + }; +} +if (!global.clearImmediate) { + global.clearImmediate = function clearImmediate(i) { + return clearTimeout(i); + }; +} +/**/ +/* eslint-disable required-modules */ 'use strict'; +/**/ +var objectKeys = objectKeys || function (obj) { + var keys = []; + for (var key in obj) { + keys.push(key); + }return keys; +}; +/**/ + var assert = require('assert'); var fork = require('child_process').fork; var path = require('path'); @@ -11,9 +37,9 @@ var runjs = path.join(__dirname, '..', '..', 'benchmark', 'run.js'); function runBenchmark(name, args, env) { var argv = []; - for (var i = 0; i < args.length; i++) { + for (var _i = 0; _i < args.length; _i++) { argv.push('--set'); - argv.push(args[i]); + argv.push(args[_i]); } argv.push(name); @@ -27,4 +53,10 @@ function runBenchmark(name, args, env) { }); } -module.exports = runBenchmark; \ No newline at end of file +module.exports = runBenchmark; + +function forEach(xs, f) { + for (var i = 0, l = xs.length; i < l; i++) { + f(xs[i], i); + } +} \ No newline at end of file diff --git a/test/common/countdown.js b/test/common/countdown.js index bb55dbb..411fb69 100644 --- a/test/common/countdown.js +++ b/test/common/countdown.js @@ -2,9 +2,35 @@ var _createClass = function () { function defineProperties(target, props) { for function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } -require('babel-polyfill'); /* eslint-disable required-modules */ +/**/ +require('babel-polyfill'); +var util = require('util'); +for (var i in util) { + exports[i] = util[i]; +} /**/ /**/ +if (!global.setImmediate) { + global.setImmediate = function setImmediate(fn) { + return setTimeout(fn.bind.apply(fn, arguments), 4); + }; +} +if (!global.clearImmediate) { + global.clearImmediate = function clearImmediate(i) { + return clearTimeout(i); + }; +} +/**/ +/* eslint-disable required-modules */ 'use strict'; +/**/ +var objectKeys = objectKeys || function (obj) { + var keys = []; + for (var key in obj) { + keys.push(key); + }return keys; +}; +/**/ + var assert = require('assert'); var kLimit = Symbol('limit'); var kCallback = Symbol('callback'); @@ -35,4 +61,10 @@ var Countdown = function () { return Countdown; }(); -module.exports = Countdown; \ No newline at end of file +module.exports = Countdown; + +function forEach(xs, f) { + for (var i = 0, l = xs.length; i < l; i++) { + f(xs[i], i); + } +} \ No newline at end of file diff --git a/test/common/dns.js b/test/common/dns.js index 4612c92..388c8df 100644 --- a/test/common/dns.js +++ b/test/common/dns.js @@ -1,8 +1,34 @@ var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }(); -require('babel-polyfill'); /* eslint-disable required-modules */ +/**/ +require('babel-polyfill'); +var util = require('util'); +for (var i in util) { + exports[i] = util[i]; +} /**/ /**/ +if (!global.setImmediate) { + global.setImmediate = function setImmediate(fn) { + return setTimeout(fn.bind.apply(fn, arguments), 4); + }; +} +if (!global.clearImmediate) { + global.clearImmediate = function clearImmediate(i) { + return clearTimeout(i); + }; +} +/**/ +/* eslint-disable required-modules */ 'use strict'; +/**/ +var objectKeys = objectKeys || function (obj) { + var keys = []; + for (var key in obj) { + keys.push(key); + }return keys; +}; +/**/ + // Naïve DNS parser/serializer. var assert = require('assert'); @@ -76,7 +102,7 @@ function parseDNSPacket(buffer) { count = _step$value[1]; parsed[sectionName] = []; - for (var i = 0; i < count; ++i) { + for (var _i = 0; _i < count; ++_i) { var _readDomainFromPacket2 = readDomainFromPacket(buffer, offset), nread = _readDomainFromPacket2.nread, domain = _readDomainFromPacket2.domain; @@ -383,4 +409,10 @@ function writeDNSPacket(parsed) { })); } -module.exports = { types: types, classes: classes, writeDNSPacket: writeDNSPacket, parseDNSPacket: parseDNSPacket }; \ No newline at end of file +module.exports = { types: types, classes: classes, writeDNSPacket: writeDNSPacket, parseDNSPacket: parseDNSPacket }; + +function forEach(xs, f) { + for (var i = 0, l = xs.length; i < l; i++) { + f(xs[i], i); + } +} \ No newline at end of file diff --git a/test/common/duplexpair.js b/test/common/duplexpair.js index 234609a..821983d 100644 --- a/test/common/duplexpair.js +++ b/test/common/duplexpair.js @@ -4,9 +4,35 @@ function _possibleConstructorReturn(self, call) { if (!self) { throw new Referen function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } -require('babel-polyfill'); /* eslint-disable required-modules */ +/**/ +require('babel-polyfill'); +var util = require('util'); +for (var i in util) { + exports[i] = util[i]; +} /**/ /**/ +if (!global.setImmediate) { + global.setImmediate = function setImmediate(fn) { + return setTimeout(fn.bind.apply(fn, arguments), 4); + }; +} +if (!global.clearImmediate) { + global.clearImmediate = function clearImmediate(i) { + return clearTimeout(i); + }; +} +/**/ +/* eslint-disable required-modules */ 'use strict'; +/**/ +var objectKeys = objectKeys || function (obj) { + var keys = []; + for (var key in obj) { + keys.push(key); + }return keys; +}; +/**/ + var _require = require('stream'), Duplex = _require.Duplex; @@ -59,4 +85,10 @@ function makeDuplexPair() { return { clientSide: clientSide, serverSide: serverSide }; } -module.exports = makeDuplexPair; \ No newline at end of file +module.exports = makeDuplexPair; + +function forEach(xs, f) { + for (var i = 0, l = xs.length; i < l; i++) { + f(xs[i], i); + } +} \ No newline at end of file diff --git a/test/common/fixtures.js b/test/common/fixtures.js index ccadf11..75f170d 100644 --- a/test/common/fixtures.js +++ b/test/common/fixtures.js @@ -1,8 +1,34 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } } -require('babel-polyfill'); /* eslint-disable required-modules */ +/**/ +require('babel-polyfill'); +var util = require('util'); +for (var i in util) { + exports[i] = util[i]; +} /**/ /**/ +if (!global.setImmediate) { + global.setImmediate = function setImmediate(fn) { + return setTimeout(fn.bind.apply(fn, arguments), 4); + }; +} +if (!global.clearImmediate) { + global.clearImmediate = function clearImmediate(i) { + return clearTimeout(i); + }; +} +/**/ +/* eslint-disable required-modules */ 'use strict'; +/**/ +var objectKeys = objectKeys || function (obj) { + var keys = []; + for (var key in obj) { + keys.push(key); + }return keys; +}; +/**/ + var path = require('path'); var fs = require('fs'); @@ -30,4 +56,10 @@ module.exports = { path: fixturesPath, readSync: readFixtureSync, readKey: readFixtureKey -}; \ No newline at end of file +}; + +function forEach(xs, f) { + for (var i = 0, l = xs.length; i < l; i++) { + f(xs[i], i); + } +} \ No newline at end of file diff --git a/test/common/index.js b/test/common/index.js index 1368446..ce627d1 100644 --- a/test/common/index.js +++ b/test/common/index.js @@ -2,7 +2,24 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } } -require('babel-polyfill'); // Copyright Joyent, Inc. and other Node contributors. +/**/ +require('babel-polyfill'); +var util = require('util'); +for (var i in util) { + exports[i] = util[i]; +} /**/ /**/ +if (!global.setImmediate) { + global.setImmediate = function setImmediate(fn) { + return setTimeout(fn.bind.apply(fn, arguments), 4); + }; +} +if (!global.clearImmediate) { + global.clearImmediate = function clearImmediate(i) { + return clearTimeout(i); + }; +} +/**/ +// Copyright Joyent, Inc. and other Node contributors. // // Permission is hereby granted, free of charge, to any person obtaining a // copy of this software and associated documentation files (the @@ -25,6 +42,16 @@ require('babel-polyfill'); // Copyright Joyent, Inc. and other Node contributors /* eslint-disable required-modules, crypto-check */ 'use strict'; + +/**/ +var objectKeys = objectKeys || function (obj) { + var keys = []; + for (var key in obj) { + keys.push(key); + }return keys; +}; +/**/ + var path = require('path'); var fs = require('fs'); var assert = require('assert'); @@ -37,8 +64,13 @@ var _require = require('child_process'), spawnSync = _require.spawnSync; var stream = require('stream'); -var util = require('util'); -var Timer = process.binding('timer_wrap').Timer; + +/**/ +var util = require('core-util-is'); +util.inherits = require('inherits'); +/**/ + +var Timer = { now: function () {} }; var _require2 = require('./fixtures'), fixturesDir = _require2.fixturesDir; @@ -63,19 +95,19 @@ exports.isOSX = process.platform === 'darwin'; exports.enoughTestMem = os.totalmem() > 0x70000000; /* 1.75 Gb */ var cpus = os.cpus(); -exports.enoughTestCpu = Array.isArray(cpus) && (cpus.length > 1 || cpus[0].speed > 999); +/*exports.enoughTestCpu = Array.isArray(cpus) && + (cpus.length > 1 || cpus[0].speed > 999);*/ exports.rootDir = exports.isWindows ? 'c:\\' : '/'; exports.projectDir = path.resolve(__dirname, '..', '..'); -exports.buildType = process.config.target_defaults.default_configuration; +//exports.buildType = process.config.target_defaults.default_configuration; // Always enable async_hooks checks in tests { - var async_wrap = process.binding('async_wrap'); - var kCheck = async_wrap.constants.kCheck; - - async_wrap.async_hook_fields[kCheck] += 1; + // const async_wrap = process.binding('async_wrap'); + // const kCheck = async_wrap.constants.kCheck; + // async_wrap.async_hook_fields[kCheck] += 1; exports.revert_force_async_hooks_checks = function () { async_wrap.async_hook_fields[kCheck] -= 1; @@ -107,26 +139,27 @@ if (process.env.NODE_TEST_WITH_ASYNC_HOOKS) { _queueDestroyAsyncId(id); }; - require('async_hooks').createHook({ - init: function (id, ty, tr, r) { + /*require('async_hooks').createHook({ + init(id, ty, tr, r) { if (initHandles[id]) { - process._rawDebug('Is same resource: ' + (r === initHandles[id].resource)); - process._rawDebug('Previous stack:\n' + initHandles[id].stack + '\n'); - throw new Error('init called twice for same id (' + id + ')'); + process._rawDebug( + `Is same resource: ${r === initHandles[id].resource}`); + process._rawDebug(`Previous stack:\n${initHandles[id].stack}\n`); + throw new Error(`init called twice for same id (${id})`); } initHandles[id] = { resource: r, stack: new Error().stack.substr(6) }; }, - before: function () {}, - after: function () {}, - destroy: function (id) { + before() { }, + after() { }, + destroy(id) { if (destroydIdsList[id] !== undefined) { process._rawDebug(destroydIdsList[id]); process._rawDebug(); - throw new Error('destroy called for same id (' + id + ')'); + throw new Error(`destroy called for same id (${id})`); } destroydIdsList[id] = new Error().stack; - } - }).enable(); + }, + }).enable();*/ } function rimrafSync(p) { @@ -154,7 +187,7 @@ function rmdirSync(p, originalEr) { if (e.code === 'ENOTDIR') throw originalEr; if (e.code === 'ENOTEMPTY' || e.code === 'EEXIST' || e.code === 'EPERM') { var enc = exports.isLinux ? 'buffer' : 'utf8'; - fs.readdirSync(p, enc).forEach(function (f) { + forEach(fs.readdirSync(p, enc), function (f) { if (f instanceof Buffer) { var buf = Buffer.concat([Buffer.from(p), Buffer.from(path.sep), f]); rimrafSync(buf); @@ -195,73 +228,83 @@ if (exports.isLinux) { 'localhost']; } -Object.defineProperty(exports, 'inFreeBSDJail', { - get: function () { - if (inFreeBSDJail !== null) return inFreeBSDJail; - - if (exports.isFreeBSD && execSync('sysctl -n security.jail.jailed').toString() === '1\n') { - inFreeBSDJail = true; - } else { - inFreeBSDJail = false; - } - return inFreeBSDJail; - } -}); - -Object.defineProperty(exports, 'localhostIPv4', { - get: function () { - if (localhostIPv4 !== null) return localhostIPv4; +/**/if (!process.browser) { + Object.defineProperty(exports, 'inFreeBSDJail', { + get: function () { + if (inFreeBSDJail !== null) return inFreeBSDJail; - if (exports.inFreeBSDJail) { - // Jailed network interfaces are a bit special - since we need to jump - // through loops, as well as this being an exception case, assume the - // user will provide this instead. - if (process.env.LOCALHOST) { - localhostIPv4 = process.env.LOCALHOST; + if (exports.isFreeBSD && execSync('sysctl -n security.jail.jailed').toString() === '1\n') { + inFreeBSDJail = true; } else { - console.error('Looks like we\'re in a FreeBSD Jail. ' + 'Please provide your default interface address ' + 'as LOCALHOST or expect some tests to fail.'); + inFreeBSDJail = false; } + return inFreeBSDJail; } + }); +} /**/ + +/**/if (!process.browser) { + Object.defineProperty(exports, 'localhostIPv4', { + get: function () { + if (localhostIPv4 !== null) return localhostIPv4; + + if (exports.inFreeBSDJail) { + // Jailed network interfaces are a bit special - since we need to jump + // through loops, as well as this being an exception case, assume the + // user will provide this instead. + if (process.env.LOCALHOST) { + localhostIPv4 = process.env.LOCALHOST; + } else { + console.error('Looks like we\'re in a FreeBSD Jail. ' + 'Please provide your default interface address ' + 'as LOCALHOST or expect some tests to fail.'); + } + } - if (localhostIPv4 === null) localhostIPv4 = '127.0.0.1'; + if (localhostIPv4 === null) localhostIPv4 = '127.0.0.1'; - return localhostIPv4; - } -}); + return localhostIPv4; + } + }); +} /**/ // opensslCli defined lazily to reduce overhead of spawnSync -Object.defineProperty(exports, 'opensslCli', { get: function () { - if (opensslCli !== null) return opensslCli; +/**/if (!process.browser) { + Object.defineProperty(exports, 'opensslCli', { get: function () { + if (opensslCli !== null) return opensslCli; - if (process.config.variables.node_shared_openssl) { - // use external command - opensslCli = 'openssl'; - } else { - // use command built from sources included in Node.js repository - opensslCli = path.join(path.dirname(process.execPath), 'openssl-cli'); - } + if (process.config.variables.node_shared_openssl) { + // use external command + opensslCli = 'openssl'; + } else { + // use command built from sources included in Node.js repository + opensslCli = path.join(path.dirname(process.execPath), 'openssl-cli'); + } - if (exports.isWindows) opensslCli += '.exe'; + if (exports.isWindows) opensslCli += '.exe'; - var opensslCmd = spawnSync(opensslCli, ['version']); - if (opensslCmd.status !== 0 || opensslCmd.error !== undefined) { - // openssl command cannot be executed - opensslCli = false; + var opensslCmd = spawnSync(opensslCli, ['version']); + if (opensslCmd.status !== 0 || opensslCmd.error !== undefined) { + // openssl command cannot be executed + opensslCli = false; + } + return opensslCli; + }, enumerable: true }); +} /**/ + +/**/if (!process.browser) { + Object.defineProperty(exports, 'hasCrypto', { + get: function () { + return Boolean(process.versions.openssl); } - return opensslCli; - }, enumerable: true }); - -Object.defineProperty(exports, 'hasCrypto', { - get: function () { - return Boolean(process.versions.openssl); - } -}); + }); +} /**/ -Object.defineProperty(exports, 'hasFipsCrypto', { - get: function () { - return exports.hasCrypto && require('crypto').fips; - } -}); +/**/if (!process.browser) { + Object.defineProperty(exports, 'hasFipsCrypto', { + get: function () { + return exports.hasCrypto && require('crypto').fips; + } + }); +} /**/ { var localRelative = path.relative(process.cwd(), exports.tmpDir + '/'); @@ -273,7 +316,7 @@ Object.defineProperty(exports, 'hasFipsCrypto', { { var iFaces = os.networkInterfaces(); var re = exports.isWindows ? /Loopback Pseudo-Interface/ : /lo/; - exports.hasIPv6 = Object.keys(iFaces).some(function (name) { + exports.hasIPv6 = objectKeys(iFaces).some(function (name) { return re.test(name) && iFaces[name].some(function (info) { return info.family === 'IPv6'; }); @@ -378,19 +421,21 @@ if (global.LTTNG_HTTP_SERVER_RESPONSE) { knownGlobals.push(LTTNG_NET_SERVER_CONNECTION); } -if (global.ArrayBuffer) { - knownGlobals.push(ArrayBuffer); - knownGlobals.push(Int8Array); - knownGlobals.push(Uint8Array); - knownGlobals.push(Uint8ClampedArray); - knownGlobals.push(Int16Array); - knownGlobals.push(Uint16Array); - knownGlobals.push(Int32Array); - knownGlobals.push(Uint32Array); - knownGlobals.push(Float32Array); - knownGlobals.push(Float64Array); - knownGlobals.push(DataView); -} +/**/if (!process.browser) { + if (global.ArrayBuffer) { + knownGlobals.push(ArrayBuffer); + knownGlobals.push(Int8Array); + knownGlobals.push(Uint8Array); + knownGlobals.push(Uint8ClampedArray); + knownGlobals.push(Int16Array); + knownGlobals.push(Uint16Array); + knownGlobals.push(Int32Array); + knownGlobals.push(Uint32Array); + knownGlobals.push(Float32Array); + knownGlobals.push(Float64Array); + knownGlobals.push(DataView); + } +} /**/ // Harmony features. if (global.Proxy) { @@ -471,7 +516,7 @@ function runCallChecks(exitCode) { } }); - failed.forEach(function (context) { + forEach(failed, function (context) { console.log('Mismatched %s function calls. Expected %s, actual %d.', context.name, context.messageSegment, context.actual); console.log(context.stack.split('\n').slice(2).join('\n')); }); @@ -594,7 +639,7 @@ function ArrayStream() { this.run = function (data) { var _this = this; - data.forEach(function (line) { + forEach(data, function (line) { _this.emit('data', line + '\n'); }); }; @@ -678,7 +723,7 @@ function expectWarningByName(name, expected) { function expectWarningByMap(warningMap) { var catchWarning = {}; - Object.keys(warningMap).forEach(function (name) { + forEach(objectKeys(warningMap), function (name) { var expected = warningMap[name]; if (typeof expected === 'string') { expected = [expected]; @@ -701,17 +746,21 @@ exports.expectWarning = function (nameOrMap, expected) { } }; -Object.defineProperty(exports, 'hasIntl', { - get: function () { - return process.binding('config').hasIntl; - } -}); +/**/if (!process.browser) { + Object.defineProperty(exports, 'hasIntl', { + get: function () { + return process.binding('config').hasIntl; + } + }); +} /**/ -Object.defineProperty(exports, 'hasSmallICU', { - get: function () { - return process.binding('config').hasSmallICU; - } -}); +/**/if (!process.browser) { + Object.defineProperty(exports, 'hasSmallICU', { + get: function () { + return process.binding('config').hasSmallICU; + } + }); +} /**/ // Useful for testing expected internal/error objects exports.expectsError = function expectsError(fn, settings, exact) { @@ -741,7 +790,7 @@ exports.expectsError = function expectsError(fn, settings, exact) { assert.strictEqual(error.name, settings.name); } if (error.constructor.name === 'AssertionError') { - ['generatedMessage', 'actual', 'expected', 'operator'].forEach(function (key) { + forEach(['generatedMessage', 'actual', 'expected', 'operator'], function (key) { if (key in settings) { var actual = error[key]; var expected = settings[key]; @@ -914,4 +963,25 @@ exports.fires = function fires(promise, error, timeoutMs) { return Promise.race([onResolvedOrRejected(promise, function () { return timeout.clear(); }), timeout]); -}; \ No newline at end of file +}; + +function forEach(xs, f) { + for (var i = 0, l = xs.length; i < l; i++) { + f(xs[i], i); + } +} + +if (!util._errnoException) { + var uv; + util._errnoException = function (err, syscall) { + if (util.isUndefined(uv)) try { + uv = process.binding('uv'); + } catch (e) {} + var errname = uv ? uv.errname(err) : ''; + var e = new Error(syscall + ' ' + errname); + e.code = errname; + e.errno = errname; + e.syscall = syscall; + return e; + }; +} \ No newline at end of file diff --git a/test/common/index.mjs b/test/common/index.mjs index 144eefe..ad89e9d 100644 --- a/test/common/index.mjs +++ b/test/common/index.mjs @@ -1,4 +1,20 @@ -require('babel-polyfill');// Flags: --experimental-modules +/**/ + require('babel-polyfill'); + var util = require('util'); + for (var i in util) exports[i] = util[i]; + /**//**/ +if (!global.setImmediate) { + global.setImmediate = function setImmediate(fn) { + return setTimeout(fn.bind.apply(fn, arguments), 4); + }; +} +if (!global.clearImmediate) { + global.clearImmediate = function clearImmediate(i) { + return clearTimeout(i); + }; +} +/**/ +// Flags: --experimental-modules /* eslint-disable required-modules */ import assert from 'assert'; @@ -107,3 +123,9 @@ process.on('exit', function() { assert.fail(`Unexpected global(s) found: ${leaked.join(', ')}`); } }); + +function forEach (xs, f) { + for (var i = 0, l = xs.length; i < l; i++) { + f(xs[i], i); + } +} diff --git a/test/common/inspector-helper.js b/test/common/inspector-helper.js index 4c5e088..6f3e818 100644 --- a/test/common/inspector-helper.js +++ b/test/common/inspector-helper.js @@ -1,6 +1,33 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } -require('babel-polyfill');'use strict'; +/**/ +require('babel-polyfill'); +var util = require('util'); +for (var i in util) { + exports[i] = util[i]; +} /**/ /**/ +if (!global.setImmediate) { + global.setImmediate = function setImmediate(fn) { + return setTimeout(fn.bind.apply(fn, arguments), 4); + }; +} +if (!global.clearImmediate) { + global.clearImmediate = function clearImmediate(i) { + return clearTimeout(i); + }; +} +/**/ +'use strict'; + +/**/ +var objectKeys = objectKeys || function (obj) { + var keys = []; + for (var key in obj) { + keys.push(key); + }return keys; +}; +/**/ + var common = require('../common'); var assert = require('assert'); var fs = require('fs'); @@ -131,8 +158,8 @@ function formatWSFrame(message) { wsHeaderBuf.writeUInt8(byte2, 1); wsHeaderBuf.writeUInt32BE(0x01020408, maskOffset); - for (var i = 0; i < messageBuf.length; i++) { - messageBuf[i] = messageBuf[i] ^ 1 << i % 4; + for (var _i = 0; _i < messageBuf.length; _i++) { + messageBuf[_i] = messageBuf[_i] ^ 1 << _i % 4; }return Buffer.concat([wsHeaderBuf.slice(0, maskOffset + 4), messageBuf]); } @@ -290,7 +317,7 @@ var InspectorSession = function () { if ('Runtime.consoleAPICalled' === notification['method']) { var params = notification['params']; if (params['type'] === type) { - var i = 0; + var _i2 = 0; var _iteratorNormalCompletion2 = true; var _didIteratorError2 = false; var _iteratorError2 = undefined; @@ -299,7 +326,7 @@ var InspectorSession = function () { for (var _iterator2 = params['args'][Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) { var value = _step2.value; - if (value['value'] !== values[i++]) return false; + if (value['value'] !== values[_i2++]) return false; } } catch (err) { _didIteratorError2 = true; @@ -316,7 +343,7 @@ var InspectorSession = function () { } } - return i === values.length; + return _i2 === values.length; } } }; @@ -485,4 +512,10 @@ module.exports = { mainScriptPath: _MAINSCRIPT, readMainScriptSource: readMainScriptSource, NodeInstance: NodeInstance -}; \ No newline at end of file +}; + +function forEach(xs, f) { + for (var i = 0, l = xs.length; i < l; i++) { + f(xs[i], i); + } +} \ No newline at end of file diff --git a/test/common/wpt.js b/test/common/wpt.js index 39bad15..22a5c89 100644 --- a/test/common/wpt.js +++ b/test/common/wpt.js @@ -1,6 +1,32 @@ -require('babel-polyfill'); /* eslint-disable required-modules */ +/**/ +require('babel-polyfill'); +var util = require('util'); +for (var i in util) { + exports[i] = util[i]; +} /**/ /**/ +if (!global.setImmediate) { + global.setImmediate = function setImmediate(fn) { + return setTimeout(fn.bind.apply(fn, arguments), 4); + }; +} +if (!global.clearImmediate) { + global.clearImmediate = function clearImmediate(i) { + return clearTimeout(i); + }; +} +/**/ +/* eslint-disable required-modules */ 'use strict'; +/**/ +var objectKeys = objectKeys || function (obj) { + var keys = []; + for (var key in obj) { + keys.push(key); + }return keys; +}; +/**/ + var assert = require('assert'); // https://github.com/w3c/testharness.js/blob/master/testharness.js @@ -29,4 +55,10 @@ module.exports = { assert_unreached: function (desc) { assert.fail('Reached unreachable code: ' + desc); } -}; \ No newline at end of file +}; + +function forEach(xs, f) { + for (var i = 0, l = xs.length; i < l; i++) { + f(xs[i], i); + } +} \ No newline at end of file diff --git a/test/parallel/test-string-decoder.js b/test/parallel/test-string-decoder.js index 20b1d23..af4f095 100644 --- a/test/parallel/test-string-decoder.js +++ b/test/parallel/test-string-decoder.js @@ -59,11 +59,8 @@ test('utf-8', bufferShim.from('C9B5A941', 'hex'), '\u0275\ufffdA'); test('utf-8', bufferShim.from('E2', 'hex'), '\ufffd'); test('utf-8', bufferShim.from('E241', 'hex'), '\ufffdA'); test('utf-8', bufferShim.from('CCCCB8', 'hex'), '\ufffd\u0338'); -test('utf-8', bufferShim.from('F0B841', 'hex'), '\ufffdA'); test('utf-8', bufferShim.from('F1CCB8', 'hex'), '\ufffd\u0338'); test('utf-8', bufferShim.from('F0FB00', 'hex'), '\ufffd\ufffd\0'); -test('utf-8', bufferShim.from('CCE2B8B8', 'hex'), '\ufffd\u2e38'); -test('utf-8', bufferShim.from('E2B8CCB8', 'hex'), '\ufffd\u0338'); test('utf-8', bufferShim.from('E2FBCC01', 'hex'), '\ufffd\ufffd\ufffd\u0001'); test('utf-8', bufferShim.from('CCB8CDB9', 'hex'), '\u0338\u0379'); // CESU-8 of U+1D40D