Skip to content

Commit

Permalink
bootstrap: mksnapshot should show JS error summaries
Browse files Browse the repository at this point in the history
  • Loading branch information
bmeck committed Apr 9, 2021
1 parent 656fb46 commit 8f5e7f7
Show file tree
Hide file tree
Showing 21 changed files with 146 additions and 62 deletions.
2 changes: 1 addition & 1 deletion lib/internal/console/constructor.js
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ function timeLogImpl(self, name, label, data) {
if (data === undefined) {
self.log('%s: %s', label, formatted);
} else {
self.log('%s: %s', label, formatted, ...new SafeArrayIterator(data));
self.log('%s: %s', label, formatted, ...SafeArrayIterator(data));
}
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/crypto/keygen.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ function parseKeyEncoding(keyType, options = {}) {
function createJob(mode, type, options) {
validateString(type, 'type');

const encoding = new SafeArrayIterator(parseKeyEncoding(type, options));
const encoding = SafeArrayIterator(parseKeyEncoding(type, options));

if (options !== undefined)
validateObject(options, 'options');
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ const aggregateTwoErrors = hideStackFrames((innerError, outerError) => {
return outerError;
}
// eslint-disable-next-line no-restricted-syntax
const err = new AggregateError(new SafeArrayIterator([
const err = new AggregateError(SafeArrayIterator([
outerError,
innerError,
]), outerError.message);
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/event_target.js
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,7 @@ function defineEventHandler(emitter, name) {
const EventEmitterMixin = (Superclass) => {
class MixedEventEmitter extends Superclass {
constructor(...args) {
args = new SafeArrayIterator(args);
args = SafeArrayIterator(args);
super(...args);
FunctionPrototypeCall(EventEmitter, this);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/fs/promises.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ async function fsCall(fn, handle, ...args) {

try {
handle[kRef]();
return await fn(handle, ...new SafeArrayIterator(args));
return await fn(handle, ...SafeArrayIterator(args));
} finally {
handle[kUnref]();
}
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/http2/compat.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ function onStreamTrailers(trailers, flags, rawTrailers) {
if (request !== undefined) {
ObjectAssign(request[kTrailers], trailers);
ArrayPrototypePush(request[kRawTrailers],
...new SafeArrayIterator(rawTrailers));
...SafeArrayIterator(rawTrailers));
}
}

Expand Down
8 changes: 4 additions & 4 deletions lib/internal/http2/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,22 +193,22 @@ let debug = require('internal/util/debuglog').debuglog('http2', (fn) => {
// this seems pretty fast, though.
function debugStream(id, sessionType, message, ...args) {
debug('Http2Stream %s [Http2Session %s]: ' + message,
id, sessionName(sessionType), ...new SafeArrayIterator(args));
id, sessionName(sessionType), ...SafeArrayIterator(args));
}

function debugStreamObj(stream, message, ...args) {
const session = stream[kSession];
const type = session ? session[kType] : undefined;
debugStream(stream[kID], type, message, ...new SafeArrayIterator(args));
debugStream(stream[kID], type, message, ...SafeArrayIterator(args));
}

function debugSession(sessionType, message, ...args) {
debug('Http2Session %s: ' + message, sessionName(sessionType),
...new SafeArrayIterator(args));
...SafeArrayIterator(args));
}

function debugSessionObj(session, message, ...args) {
debugSession(session[kType], message, ...new SafeArrayIterator(args));
debugSession(session[kType], message, ...SafeArrayIterator(args));
}

const kMaxFrameSize = (2 ** 24) - 1;
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/legacy/processbinding.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const { types } = require('util');

module.exports = {
util() {
return ObjectFromEntries(new SafeArrayIterator(ArrayPrototypeFilter(
return ObjectFromEntries(SafeArrayIterator(ArrayPrototypeFilter(
ObjectEntries(types),
({ 0: key }) => {
return ArrayPrototypeIncludes([
Expand Down
6 changes: 3 additions & 3 deletions lib/internal/modules/esm/module_job.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ class ModuleJob {
});

if (promises !== undefined)
await PromiseAll(new SafeArrayIterator(promises));
await PromiseAll(SafeArrayIterator(promises));

return PromiseAll(new SafeArrayIterator(dependencyJobs));
return PromiseAll(SafeArrayIterator(dependencyJobs));
};
// Promise for the list of all dependencyJobs.
this.linked = link();
Expand Down Expand Up @@ -91,7 +91,7 @@ class ModuleJob {
}
jobsInGraph.add(moduleJob);
const dependencyJobs = await moduleJob.linked;
return PromiseAll(new SafeArrayIterator(
return PromiseAll(SafeArrayIterator(
ArrayPrototypeMap(dependencyJobs, addJobsToDependencyGraph)));
};
await addJobsToDependencyGraph(this);
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/modules/esm/translators.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ function cjsPreparseModuleExports(filename) {
reexports = [];
}

const exportNames = new SafeSet(new SafeArrayIterator(exports));
const exportNames = new SafeSet(SafeArrayIterator(exports));

// Set first for cycles.
cjsParseCache.set(module, { source, exportNames, loaded });
Expand Down
74 changes: 43 additions & 31 deletions lib/internal/per_context/primordials.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ const {
ArrayPrototypeForEach,
FunctionPrototypeCall,
Map,
ObjectCreate,
ObjectFreeze,
ObjectSetPrototypeOf,
Set,
Expand All @@ -239,54 +240,65 @@ const {
WeakSet,
} = primordials;

// Because these functions are used by `makeSafe`, which is exposed
// on the `primordials` object, it's important to use const references
// to the primordials that they use:
const createSafeIterator = (factory, next) => {
class SafeIterator {
constructor(iterable) {
this._iterator = factory(iterable);
}
next() {
return next(this._iterator);
}
[SymbolIterator]() {
return this;
function returnThis() {
return this;
}
ObjectFreeze(returnThis);
primordials.returnThis = returnThis;

const copyProps = (src, dest) => {
ArrayPrototypeForEach(ReflectOwnKeys(src), (key) => {
if (!ReflectGetOwnPropertyDescriptor(dest, key)) {
ReflectDefineProperty(
dest,
key,
ReflectGetOwnPropertyDescriptor(src, key));
}
});
};

/**
* Because these functions are used by `makeSafe`, which is exposed
* on the `primordials` object, it's important to use const references
* to the primordials that they use:
*
* @template {Iterable} T
* @param {(this: T): Iterator} factory
* @param {ReturnType<T[SymbolIterator]>} proto
* @returns {{(T): ReturnType<T[SymbolIterator]>}
*/
const createSafeIterator = (factory, proto) => {
const safeProto = ObjectCreate(null);
copyProps(proto, safeProto);
safeProto[SymbolIterator] = returnThis;
function SafeIterator(iterable) {
const iter = FunctionPrototypeCall(factory, iterable);
ObjectSetPrototypeOf(iter, safeProto);
return iter;
}
SafeIterator.prototype = safeProto;
ObjectSetPrototypeOf(SafeIterator.prototype, null);
ObjectFreeze(SafeIterator.prototype);
ObjectFreeze(SafeIterator);
return SafeIterator;
};

primordials.SafeArrayIterator = createSafeIterator(
primordials.ArrayPrototypeSymbolIterator,
primordials.ArrayIteratorPrototypeNext
primordials.Array.prototype[SymbolIterator],
primordials.ArrayIterator.prototype
);
primordials.SafeStringIterator = createSafeIterator(
primordials.StringPrototypeSymbolIterator,
primordials.StringIteratorPrototypeNext
primordials.String.prototype[SymbolIterator],
primordials.StringIterator.prototype
);

const copyProps = (src, dest) => {
ArrayPrototypeForEach(ReflectOwnKeys(src), (key) => {
if (!ReflectGetOwnPropertyDescriptor(dest, key)) {
ReflectDefineProperty(
dest,
key,
ReflectGetOwnPropertyDescriptor(src, key));
}
});
};

/**
* @type {typeof primordials.makeSafe}
*/
const makeSafe = (unsafe, safe) => {
if (SymbolIterator in unsafe.prototype) {
const dummy = new unsafe();
let next; // We can reuse the same `next` method.
let proto; // We can reuse the same proto

ArrayPrototypeForEach(ReflectOwnKeys(unsafe.prototype), (key) => {
if (!ReflectGetOwnPropertyDescriptor(safe.prototype, key)) {
Expand All @@ -297,8 +309,8 @@ const makeSafe = (unsafe, safe) => {
SymbolIterator in (FunctionPrototypeCall(desc.value, dummy) ?? {})
) {
const createIterator = uncurryThis(desc.value);
next ??= uncurryThis(createIterator(dummy).next);
const SafeIterator = createSafeIterator(createIterator, next);
proto ??= ObjectGetPrototypeOf(createIterator(dummy));
const SafeIterator = createSafeIterator(desc.value, proto);
desc.value = function() {
return new SafeIterator(this);
};
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/perf/nodetiming.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ function getMilestoneTimestamp(milestoneIdx) {
return ns / 1e6 - timeOrigin;
}

const readOnlyAttributes = new SafeSet(new SafeArrayIterator([
const readOnlyAttributes = new SafeSet(SafeArrayIterator([
'nodeStart',
'v8Start',
'environment',
Expand Down
53 changes: 48 additions & 5 deletions lib/internal/policy/manifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,37 @@ class Manifest {
cascade
) => {
let parentDeps;
return (toSpecifier, conditions) => {
let normalized = false;
return (fromHREF, toSpecifier, conditions) => {
try {
if (RegExpPrototypeTest(kRelativeURLStringPattern, toSpecifier)) {
toSpecifier = new URL(toSpecifier, fromHREF).href;
} else {
toSpecifier = new URL(toSpecifier).href;
}
} catch {
}
if (!normalized) {
let normalizedDependencyMap = ObjectCreate(null);
for (var k in dependencyMap) {
let target = dependencyMap[k];
try {
if (RegExpPrototypeTest(/\.?\.?\//, k)) {
k = new URL(k, manifestURL).href;
} else {
k = new URL(k).href;
}
} catch {
}
try {
normalizedDependencyMap[k] = target;
} catch {
//
}
}
dependencyMap = normalizedDependencyMap;
normalized = true;
}
if (toSpecifier in dependencyMap !== true) {
if (cascade === true) {
/** @type {string | null} */
Expand All @@ -230,7 +260,7 @@ class Manifest {
return null;
}
const to = searchDependencies(
resourceHREF,
fromHREF,
dependencyMap[toSpecifier],
conditions);
if (to === true) {
Expand Down Expand Up @@ -448,7 +478,9 @@ class Manifest {

#createResolver = (resolve) => {
return {
resolve: (to, conditions) => resolve(`${to}`, conditions),
resolve: (from, to, conditions) => {
return resolve(from, `${to}`, conditions);
},
reaction: this.#reaction
};
}
Expand All @@ -460,16 +492,27 @@ class Manifest {
const requesterHREF = `${requester}`;
const dependencies = this.#resourceDependencies;
if (dependencies.has(requesterHREF)) {
return this.#createResolver(
const {resolve, reaction} = this.#createResolver(
dependencies.get(requesterHREF) ||
(() => null)
);
return {
reaction,
resolve: (...args) => resolve(requesterHREF, ...args)
};
}
const scopes = this.#scopeDependencies;
if (scopes.size !== 0) {
const scopeHREF = this.#findScopeHREF(requesterHREF);
if (typeof scopeHREF === 'string') {
return this.#createResolver(scopes.get(scopeHREF));
const {resolve, reaction} = this.#createResolver(
scopes.get(scopeHREF) ||
(() => null)
);
return {
reaction,
resolve: (...args) => resolve(requesterHREF, ...args),
}
}
}
return this.#createResolver(() => null);
Expand Down
4 changes: 2 additions & 2 deletions lib/internal/process/per_thread.js
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ function buildAllowedFlags() {

entries() {
this[kInternal].set ??=
new Set(new SafeArrayIterator(this[kInternal].array));
new Set(SafeArrayIterator(this[kInternal].array));
return SetPrototypeEntries(this[kInternal].set);
}

Expand All @@ -362,7 +362,7 @@ function buildAllowedFlags() {

values() {
this[kInternal].set ??=
new Set(new SafeArrayIterator(this[kInternal].array));
new Set(SafeArrayIterator(this[kInternal].array));
return SetPrototypeValues(this[kInternal].set);
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/repl/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ function setupPreview(repl, contextSymbol, bufferSymbol, active) {
getStringWidth(inspected) > maxColumns) {
maxColumns -= 4 + (repl.useColors ? 0 : 3);
let res = '';
for (const char of new SafeStringIterator(inspected)) {
for (const char of SafeStringIterator(inspected)) {
maxColumns -= getStringWidth(char);
if (maxColumns < 0)
break;
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/source_map/prepare_stack_trace.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ function getErrorSource(
// Display ^ in appropriate position, regardless of whether tabs or
// spaces are used:
let prefix = '';
for (const character of new SafeStringIterator(
for (const character of SafeStringIterator(
StringPrototypeSlice(line, 0, originalColumn + 1))) {
prefix += (character === '\t') ? '\t' :
StringPrototypeRepeat(' ', getStringWidth(character));
Expand Down
4 changes: 2 additions & 2 deletions lib/internal/util/debuglog.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,15 @@ function debuglog(set, cb) {
debug = debuglogImpl(enabled, set);
if (typeof cb === 'function')
cb(debug);
debug(...new SafeArrayIterator(args));
debug(...SafeArrayIterator(args));
};
let enabled;
let test = () => {
init();
test = () => enabled;
return enabled;
};
const logger = (...args) => debug(...new SafeArrayIterator(args));
const logger = (...args) => debug(...SafeArrayIterator(args));
ObjectDefineProperty(logger, 'enabled', {
get() {
return test();
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/util/inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -2038,7 +2038,7 @@ if (internalBinding('config').hasIntl) {
if (removeControlChars)
str = stripVTControlCharacters(str);
str = StringPrototypeNormalize(str, 'NFC');
for (const char of new SafeStringIterator(str)) {
for (const char of SafeStringIterator(str)) {
const code = StringPrototypeCodePointAt(char, 0);
if (isFullWidthCodePoint(code)) {
width += 2;
Expand Down
Loading

0 comments on commit 8f5e7f7

Please sign in to comment.