Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion common.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

# Reset this number to 0 on major V8 upgrades.
# Increment by one for each non-official patch applied to deps/v8.
'v8_embedder_string': '-node.30',
'v8_embedder_string': '-node.31',

##### V8 defaults for Node.js #####

Expand Down
1 change: 0 additions & 1 deletion deps/v8/src/parsing/parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,6 @@ FunctionLiteral* Parser::ParseProgram(Isolate* isolate, ParseInfo* info) {
Scope::DeserializationMode::kIncludingVariables);

scanner_.Initialize();
scanner_.SkipHashBang();
FunctionLiteral* result = DoParseProgram(isolate, info);
MaybeResetCharacterStream(info, result);
MaybeProcessSourceRanges(info, result, stack_limit_);
Expand Down
4 changes: 0 additions & 4 deletions deps/v8/src/parsing/preparser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,6 @@ PreParser::PreParseResult PreParser::PreParseProgram() {
scope->set_is_being_lazily_parsed(true);
#endif

// Note: We should only skip the hashbang in non-Eval scripts
// (currently, Eval is not handled by the PreParser).
scanner()->SkipHashBang();

// ModuleDeclarationInstantiation for Source Text Module Records creates a
// new Module Environment Record whose outer lexical environment record is
// the global scope.
Expand Down
4 changes: 4 additions & 0 deletions deps/v8/src/parsing/scanner-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,10 @@ V8_INLINE Token::Value Scanner::ScanSingleToken() {
return ScanTemplateSpan();

case Token::PRIVATE_NAME:
if (source_pos() == 0 && Peek() == '!') {
token = SkipSingleLineComment();
continue;
}
return ScanPrivateName();

case Token::WHITESPACE:
Expand Down
7 changes: 0 additions & 7 deletions deps/v8/src/parsing/scanner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -314,13 +314,6 @@ Token::Value Scanner::SkipMultiLineComment() {
return Token::ILLEGAL;
}

void Scanner::SkipHashBang() {
if (c0_ == '#' && Peek() == '!' && source_pos() == 0) {
SkipSingleLineComment();
Scan();
}
}

Token::Value Scanner::ScanHtmlComment() {
// Check for <!-- comments.
DCHECK_EQ(c0_, '!');
Expand Down
3 changes: 0 additions & 3 deletions deps/v8/src/parsing/scanner.h
Original file line number Diff line number Diff line change
Expand Up @@ -421,9 +421,6 @@ class V8_EXPORT_PRIVATE Scanner {

const Utf16CharacterStream* stream() const { return source_; }

// If the next characters in the stream are "#!", the line is skipped.
void SkipHashBang();

private:
// Scoped helper for saving & restoring scanner error state.
// This is used for tagged template literals, in which normally forbidden
Expand Down
12 changes: 12 additions & 0 deletions deps/v8/test/message/fail/hashbang-incomplete-string.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env d8
// Copyright 2015 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
//

const x = 'valid code';

'incomplete string

const y = 'even more valid code!';
5 changes: 5 additions & 0 deletions deps/v8/test/message/fail/hashbang-incomplete-string.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
*%(basename)s:10: SyntaxError: Invalid or unexpected token
'incomplete string
^^^^^^^^^^^^^^^^^^

SyntaxError: Invalid or unexpected token
6 changes: 3 additions & 3 deletions lib/internal/encoding.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const {
} = require('internal/util');

const {
isArrayBuffer,
isAnyArrayBuffer,
isArrayBufferView,
isUint8Array
} = require('internal/util/types');
Expand Down Expand Up @@ -404,7 +404,7 @@ function makeTextDecoderICU() {

decode(input = empty, options = {}) {
validateDecoder(this);
if (isArrayBuffer(input)) {
if (isAnyArrayBuffer(input)) {
input = lazyBuffer().from(input);
} else if (!isArrayBufferView(input)) {
throw new ERR_INVALID_ARG_TYPE('input',
Expand Down Expand Up @@ -469,7 +469,7 @@ function makeTextDecoderJS() {

decode(input = empty, options = {}) {
validateDecoder(this);
if (isArrayBuffer(input)) {
if (isAnyArrayBuffer(input)) {
input = lazyBuffer().from(input);
} else if (isArrayBufferView(input)) {
input = lazyBuffer().from(input.buffer, input.byteOffset,
Expand Down
59 changes: 43 additions & 16 deletions lib/internal/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -1078,29 +1078,50 @@ E('ERR_INVALID_FILE_URL_PATH', 'File URL path %s', TypeError);
E('ERR_INVALID_HANDLE_TYPE', 'This handle type cannot be sent', TypeError);
E('ERR_INVALID_HTTP_TOKEN', '%s must be a valid HTTP token ["%s"]', TypeError);
E('ERR_INVALID_IP_ADDRESS', 'Invalid IP address: %s', TypeError);
E('ERR_INVALID_MODULE_SPECIFIER', (pkgPath, subpath) => {
assert(subpath !== '.');
return `Package subpath '${subpath}' is not a valid module request for the ` +
`"exports" resolution of ${pkgPath}${sep}package.json`;
E('ERR_INVALID_MODULE_SPECIFIER', (pkgPath, subpath, base = undefined) => {
if (subpath === undefined) {
return `Invalid package name '${pkgPath}' imported from ${base}`;
} else if (base === undefined) {
assert(subpath !== '.');
return `Package subpath '${subpath}' is not a valid module request for ` +
`the "exports" resolution of ${pkgPath}${sep}package.json`;
} else {
return `Package subpath '${subpath}' is not a valid module request for ` +
`the "exports" resolution of ${pkgPath} imported from ${base}`;
}
}, TypeError);
E('ERR_INVALID_OPT_VALUE', (name, value) =>
`The value "${String(value)}" is invalid for option "${name}"`,
TypeError,
RangeError);
E('ERR_INVALID_OPT_VALUE_ENCODING',
'The value "%s" is invalid for option "encoding"', TypeError);
E('ERR_INVALID_PACKAGE_CONFIG',
`Invalid package config %s${sep}package.json, %s`, Error);
E('ERR_INVALID_PACKAGE_TARGET', (pkgPath, key, subpath, target) => {
if (key === '.') {
return `Invalid "exports" main target ${JSONStringify(target)} defined ` +
E('ERR_INVALID_PACKAGE_CONFIG', (path, message, hasMessage = true) => {
if (hasMessage)
return `Invalid package config ${path}${sep}package.json, ${message}`;
else
return `Invalid JSON in ${path} imported from ${message}`;
}, Error);
E('ERR_INVALID_PACKAGE_TARGET',
(pkgPath, key, subpath, target, base = undefined) => {
if (key === null) {
if (subpath !== '') {
return `Invalid "exports" target ${JSONStringify(target)} defined ` +
`for '${subpath}' in the package config ${pkgPath} imported from ` +
base;
} else {
return `Invalid "exports" main target ${target} defined in the ` +
`package config ${pkgPath} imported from ${base}.`;
}
} else if (key === '.') {
return `Invalid "exports" main target ${JSONStringify(target)} defined ` +
`in the package config ${pkgPath}${sep}package.json`;
} else {
return `Invalid "exports" target ${JSONStringify(target)} defined for '${
StringPrototypeSlice(key, 0, -subpath.length || key.length)}' in the ` +
} else {
return `Invalid "exports" target ${JSONStringify(target)} defined for '${
StringPrototypeSlice(key, 0, -subpath.length || key.length)}' in the ` +
`package config ${pkgPath}${sep}package.json`;
}
}, Error);
}
}, Error);
E('ERR_INVALID_PERFORMANCE_MARK',
'The "%s" performance mark has not been set', Error);
E('ERR_INVALID_PROTOCOL',
Expand Down Expand Up @@ -1211,6 +1232,9 @@ E('ERR_MISSING_DYNAMIC_INSTANTIATE_HOOK',
'The ES Module loader may not return a format of \'dynamic\' when no ' +
'dynamicInstantiate function was provided', Error);
E('ERR_MISSING_OPTION', '%s is required', TypeError);
E('ERR_MODULE_NOT_FOUND', (path, base, type = 'package') => {
return `Cannot find ${type} '${path}' imported from ${base}`;
}, Error);
E('ERR_MULTIPLE_CALLBACK', 'Callback called multiple times', Error);
E('ERR_NAPI_CONS_FUNCTION', 'Constructor must be a function', TypeError);
E('ERR_NAPI_INVALID_DATAVIEW_ARGS',
Expand Down Expand Up @@ -1245,12 +1269,15 @@ E('ERR_OUT_OF_RANGE',
msg += ` It must be ${range}. Received ${received}`;
return msg;
}, RangeError);
E('ERR_PACKAGE_PATH_NOT_EXPORTED', (pkgPath, subpath) => {
E('ERR_PACKAGE_PATH_NOT_EXPORTED', (pkgPath, subpath, base = undefined) => {
if (subpath === '.') {
return `No "exports" main resolved in ${pkgPath}${sep}package.json`;
} else {
} else if (base === undefined) {
return `Package subpath '${subpath}' is not defined by "exports" in ${
pkgPath}${sep}package.json`;
} else {
return `Package subpath '${subpath}' is not defined by "exports" in ${
pkgPath} imported from ${base}`;
}
}, Error);
E('ERR_REQUIRE_ESM',
Expand Down
15 changes: 5 additions & 10 deletions lib/internal/modules/esm/get_format.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
'use strict';

const { StringPrototypeStartsWith } = primordials;
const { extname } = require('path');
const { getOptionValue } = require('internal/options');

const experimentalJsonModules = getOptionValue('--experimental-json-modules');
const experimentalSpeciferResolution =
getOptionValue('--experimental-specifier-resolution');
const experimentalWasmModules = getOptionValue('--experimental-wasm-modules');
const { getPackageType } = internalBinding('module_wrap');
const { getPackageType } = require('internal/modules/esm/resolve');
const { URL, fileURLToPath } = require('internal/url');
const { ERR_UNKNOWN_FILE_EXTENSION } = require('internal/errors').codes;

// const TYPE_NONE = 0;
// const TYPE_COMMONJS = 1;
const TYPE_MODULE = 2;

const extensionFormatMap = {
'__proto__': null,
'.cjs': 'commonjs',
Expand All @@ -37,8 +33,8 @@ if (experimentalWasmModules)
if (experimentalJsonModules)
extensionFormatMap['.json'] = legacyExtensionFormatMap['.json'] = 'json';

function defaultGetFormat(url, context, defaultGetFormat) {
if (url.startsWith('nodejs:')) {
function defaultGetFormat(url, context, defaultGetFormatUnused) {
if (StringPrototypeStartsWith(url, 'nodejs:')) {
return { format: 'builtin' };
}
const parsed = new URL(url);
Expand All @@ -55,8 +51,7 @@ function defaultGetFormat(url, context, defaultGetFormat) {
const ext = extname(parsed.pathname);
let format;
if (ext === '.js') {
format = getPackageType(parsed.href) === TYPE_MODULE ?
'module' : 'commonjs';
format = getPackageType(parsed.href) === 'module' ? 'module' : 'commonjs';
} else {
format = extensionFormatMap[ext];
}
Expand Down
Loading