Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/nodejs/node into http_compat
Browse files Browse the repository at this point in the history
  • Loading branch information
sagitsofan committed Dec 15, 2018
2 parents 058a029 + 0bf7d41 commit 56f165c
Show file tree
Hide file tree
Showing 12 changed files with 271 additions and 68 deletions.
4 changes: 0 additions & 4 deletions doc/api/util.md
Original file line number Diff line number Diff line change
Expand Up @@ -449,10 +449,6 @@ changes:
* `showProxy` {boolean} If `true`, then objects and functions that are
`Proxy` objects will be introspected to show their `target` and `handler`
objects. **Default:** `false`.
<!--
TODO(BridgeAR): Deprecate `maxArrayLength` and replace it with
`maxEntries`.
-->
* `maxArrayLength` {integer} Specifies the maximum number of `Array`,
[`TypedArray`][], [`WeakMap`][] and [`WeakSet`][] elements to include when
formatting. Set to `null` or `Infinity` to show all elements. Set to `0` or
Expand Down
6 changes: 2 additions & 4 deletions lib/buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@ const {
isArrayBufferView,
isUint8Array
} = require('internal/util/types');
const {
pendingDeprecation
} = internalBinding('config');

const {
ERR_BUFFER_OUT_OF_BOUNDS,
ERR_OUT_OF_RANGE,
Expand Down Expand Up @@ -138,7 +136,7 @@ const bufferWarning = 'Buffer() is deprecated due to security and usability ' +
function showFlaggedDeprecation() {
if (bufferWarningAlreadyEmitted ||
++nodeModulesCheckCounter > 10000 ||
(!pendingDeprecation &&
(!require('internal/options').getOptionValue('--pending-deprecation') &&
isInsideNodeModules())) {
// We don't emit a warning, because we either:
// - Already did so, or
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/bootstrap/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ function startup() {
{
// Install legacy getters on the `util` binding for typechecking.
// TODO(addaleax): Turn into a full runtime deprecation.
const { pendingDeprecation } = internalBinding('config');
const pendingDeprecation = getOptionValue('--pending-deprecation');
const utilBinding = internalBinding('util');
const types = internalBinding('types');
for (const name of [
Expand Down
2 changes: 0 additions & 2 deletions lib/internal/util/inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,6 @@ function inspect(value, opts) {
colors: inspectDefaultOptions.colors,
customInspect: inspectDefaultOptions.customInspect,
showProxy: inspectDefaultOptions.showProxy,
// TODO(BridgeAR): Deprecate `maxArrayLength` and replace it with
// `maxEntries`.
maxArrayLength: inspectDefaultOptions.maxArrayLength,
breakLength: inspectDefaultOptions.breakLength,
compact: inspectDefaultOptions.compact,
Expand Down
3 changes: 0 additions & 3 deletions src/node_config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,6 @@ static void Initialize(Local<Object> target,
if (env->options()->experimental_repl_await)
READONLY_TRUE_PROPERTY(target, "experimentalREPLAwait");

if (env->options()->pending_deprecation)
READONLY_TRUE_PROPERTY(target, "pendingDeprecation");

if (env->options()->expose_internals)
READONLY_TRUE_PROPERTY(target, "exposeInternals");

Expand Down
139 changes: 99 additions & 40 deletions test/common/wpt.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,20 +66,92 @@ class ResourceLoader {
}
}

class StatusRule {
constructor(key, value, pattern = undefined) {
this.key = key;
this.requires = value.requires || [];
this.fail = value.fail;
this.skip = value.skip;
if (pattern) {
this.pattern = this.transformPattern(pattern);
}
// TODO(joyeecheung): implement this
this.scope = value.scope;
this.comment = value.comment;
}

/**
* Transform a filename pattern into a RegExp
* @param {string} pattern
* @returns {RegExp}
*/
transformPattern(pattern) {
const result = pattern.replace(/[-/\\^$+?.()|[\]{}]/g, '\\$&');
return new RegExp(result.replace('*', '.*'));
}
}

class StatusRuleSet {
constructor() {
// We use two sets of rules to speed up matching
this.exactMatch = {};
this.patternMatch = [];
}

/**
* @param {object} rules
*/
addRules(rules) {
for (const key of Object.keys(rules)) {
if (key.includes('*')) {
this.patternMatch.push(new StatusRule(key, rules[key], key));
} else {
this.exactMatch[key] = new StatusRule(key, rules[key]);
}
}
}

match(file) {
const result = [];
const exact = this.exactMatch[file];
if (exact) {
result.push(exact);
}
for (const item of this.patternMatch) {
if (item.pattern.test(file)) {
result.push(item);
}
}
return result;
}
}

class WPTTest {
/**
* @param {string} mod
* @param {string} filename
* @param {string[]} requires
* @param {string | undefined} failReason
* @param {string | undefined} skipReason
* @param {StatusRule[]} rules
*/
constructor(mod, filename, requires, failReason, skipReason) {
constructor(mod, filename, rules) {
this.module = mod; // name of the WPT module, e.g. 'url'
this.filename = filename; // name of the test file
this.requires = requires;
this.failReason = failReason;
this.skipReason = skipReason;

this.requires = new Set();
this.failReasons = [];
this.skipReasons = [];
for (const item of rules) {
if (item.requires.length) {
for (const req of item.requires) {
this.requires.add(req);
}
}
if (item.fail) {
this.failReasons.push(item.fail);
}
if (item.skip) {
this.skipReasons.push(item.skip);
}
}
}

getAbsolutePath() {
Expand All @@ -90,54 +162,37 @@ class WPTTest {
return fs.readFileSync(this.getAbsolutePath(), 'utf8');
}

shouldSkip() {
return this.failReason || this.skipReason;
}

requireIntl() {
return this.requires.includes('intl');
return this.requires.has('intl');
}
}

class StatusLoader {
constructor(path) {
this.path = path;
this.loaded = false;
this.status = null;
this.rules = new StatusRuleSet();
/** @type {WPTTest[]} */
this.tests = [];
}

loadTest(file) {
let requires = [];
let failReason;
let skipReason;
if (this.status[file]) {
requires = this.status[file].requires || [];
failReason = this.status[file].fail;
skipReason = this.status[file].skip;
}
return new WPTTest(this.path, file, requires,
failReason, skipReason);
}

load() {
const dir = path.join(__dirname, '..', 'wpt');
const statusFile = path.join(dir, 'status', `${this.path}.json`);
const result = JSON.parse(fs.readFileSync(statusFile, 'utf8'));
this.status = result;
this.rules.addRules(result);

const list = fs.readdirSync(fixtures.path('wpt', this.path));

for (const file of list) {
this.tests.push(this.loadTest(file));
if (!(/\.\w+\.js$/.test(file))) {
continue;
}
const match = this.rules.match(file);
this.tests.push(new WPTTest(this.path, file, match));
}
this.loaded = true;
}

get jsTests() {
return this.tests.filter((test) => test.filename.endsWith('.js'));
}
}

const PASSED = 1;
Expand All @@ -156,7 +211,7 @@ class WPTRunner {
this.status = new StatusLoader(path);
this.status.load();
this.tests = new Map(
this.status.jsTests.map((item) => [item.filename, item])
this.status.tests.map((item) => [item.filename, item])
);

this.results = new Map();
Expand All @@ -171,7 +226,10 @@ class WPTRunner {
*/
copyGlobalsFromObject(obj, names) {
for (const name of names) {
const desc = Object.getOwnPropertyDescriptor(global, name);
const desc = Object.getOwnPropertyDescriptor(obj, name);
if (!desc) {
assert.fail(`${name} does not exist on the object`);
}
this.globals.set(name, desc);
}
}
Expand Down Expand Up @@ -328,8 +386,9 @@ class WPTRunner {
for (const item of items) {
switch (item.type) {
case FAILED: {
if (test.failReason) {
if (test.failReasons.length) {
console.log(`[EXPECTED_FAILURE] ${item.test.name}`);
console.log(test.failReasons.join('; '));
} else {
console.log(`[UNEXPECTED_FAILURE] ${item.test.name}`);
unexpectedFailures.push([title, filename, item]);
Expand Down Expand Up @@ -386,10 +445,10 @@ class WPTRunner {
});
}

skip(filename, reason) {
skip(filename, reasons) {
this.addResult(filename, {
type: SKIPPED,
reason
reason: reasons.join('; ')
});
}

Expand Down Expand Up @@ -435,13 +494,13 @@ class WPTRunner {
const queue = [];
for (const test of this.tests.values()) {
const filename = test.filename;
if (test.skipReason) {
this.skip(filename, test.skipReason);
if (test.skipReasons.length > 0) {
this.skip(filename, test.skipReasons);
continue;
}

if (!common.hasIntl && test.requireIntl()) {
this.skip(filename, 'missing Intl');
this.skip(filename, [ 'missing Intl' ]);
continue;
}

Expand Down
6 changes: 6 additions & 0 deletions test/parallel/parallel.status
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,19 @@ prefix parallel
# sample-test : PASS,FLAKY

[true] # This section applies to all platforms
# https://github.com/nodejs/node/issues/25029
test-child-process-execfile: PASS,FLAKY
# https://github.com/nodejs/node/issues/23207
test-net-connect-options-port: PASS,FLAKY
# https://github.com/nodejs/node/issues/25033
test-child-process-exit-code: PASS,FLAKY

[$system==win32]
test-http2-pipe: PASS,FLAKY
test-worker-syntax-error: PASS,FLAKY
test-worker-syntax-error-file: PASS,FLAKY
# https://github.com/nodejs/node/issues/23277
test-worker-memory: PASS,FLAKY

[$system==linux]

Expand Down
32 changes: 21 additions & 11 deletions test/parallel/test-pending-deprecation.js
Original file line number Diff line number Diff line change
@@ -1,44 +1,53 @@
'use strict';

// Tests that --pending-deprecation and NODE_PENDING_DEPRECATION both
// set the process.binding('config').pendingDeprecation flag that is
// used to determine if pending deprecation messages should be shown.
// The test is performed by launching two child processes that run
// Flags: --expose-internals
// Tests that --pending-deprecation and NODE_PENDING_DEPRECATION both set the
// `require('internal/options').getOptionValue('--pending-deprecation')`
// flag that is used to determine if pending deprecation messages should be
// shown. The test is performed by launching two child processes that run
// this same test script with different arguments. If those exit with
// code 0, then the test passes. If they don't, it fails.

// TODO(joyeecheung): instead of testing internals, test the actual features
// pending deprecations.

const common = require('../common');

const assert = require('assert');
const config = process.binding('config');
const fork = require('child_process').fork;
const { getOptionValue } = require('internal/options');

function message(name) {
return `${name} did not set the process.binding('config').` +
'pendingDeprecation flag.';
return `${name} did not affect getOptionValue('--pending-deprecation')`;
}

switch (process.argv[2]) {
case 'env':
case 'switch':
assert.strictEqual(config.pendingDeprecation, true);
assert.strictEqual(
getOptionValue('--pending-deprecation'),
true
);
break;
default:
// Verify that the flag is off by default.
const envvar = process.env.NODE_PENDING_DEPRECATION;
assert.strictEqual(config.pendingDeprecation, envvar && envvar[0] === '1');
assert.strictEqual(
getOptionValue('--pending-deprecation'),
!!(envvar && envvar[0] === '1')
);

// Test the --pending-deprecation command line switch.
fork(__filename, ['switch'], {
execArgv: ['--pending-deprecation'],
execArgv: ['--pending-deprecation', '--expose-internals'],
silent: true
}).on('exit', common.mustCall((code) => {
assert.strictEqual(code, 0, message('--pending-deprecation'));
}));

// Test the --pending_deprecation command line switch.
fork(__filename, ['switch'], {
execArgv: ['--pending_deprecation'],
execArgv: ['--pending_deprecation', '--expose-internals'],
silent: true
}).on('exit', common.mustCall((code) => {
assert.strictEqual(code, 0, message('--pending_deprecation'));
Expand All @@ -47,6 +56,7 @@ switch (process.argv[2]) {
// Test the NODE_PENDING_DEPRECATION environment var.
fork(__filename, ['env'], {
env: Object.assign({}, process.env, { NODE_PENDING_DEPRECATION: 1 }),
execArgv: ['--expose-internals'],
silent: true
}).on('exit', common.mustCall((code) => {
assert.strictEqual(code, 0, message('NODE_PENDING_DEPRECATION'));
Expand Down
Loading

0 comments on commit 56f165c

Please sign in to comment.