Skip to content

Commit a4fcc32

Browse files
authored
feat: upgrade to Node 12 (electron#17838)
* fix: add boringssl backport to support node upgrade * fix: Update node_includes.h, add DCHECK macros * fix: Update node Debug Options parser usage * fix: Fix asar setup * fix: using v8Util in isolated context * fix: make "process" available in preload scripts * fix: use proper options parser and remove setting of _breakFirstLine _breakFirstLine was being set on the process, but that has changed in node 12 and so is no longer needed. Node will handle it properly when --inspect-brk is provided * chore: update node dep sha * fix: process.binding => _linkedBinding in sandboxed isolated preload * fix: make original-fs work with streams * build: override node module version * fix: use _linkedBinding in content_script/init.js * chore: update node ref in DEPS * build: node_module_version should be 73
1 parent e1acfff commit a4fcc32

File tree

15 files changed

+249
-32
lines changed

15 files changed

+249
-32
lines changed

DEPS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ vars = {
1212
'chromium_version':
1313
'1e9f9a24aa12bea9cf194a82a7e249bd1242ec4f',
1414
'node_version':
15-
'2dc0f8811b2b295c08d797b8a11b030234c98502',
15+
'696d8fb66d6f65fc82869d390e0d2078970b1eb4',
1616

1717
'boto_version': 'f7574aa6cc2c819430c1f05e9a1a1a666ef8169b',
1818
'pyyaml_version': '3.12',

atom/browser/node_debugger.cc

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,27 +37,20 @@ void NodeDebugger::Start() {
3737
}
3838

3939
node::DebugOptions options;
40+
node::options_parser::DebugOptionsParser options_parser;
4041
std::vector<std::string> exec_args;
4142
std::vector<std::string> v8_args;
4243
std::vector<std::string> errors;
4344

44-
node::options_parser::DebugOptionsParser::instance.Parse(
45-
&args, &exec_args, &v8_args, &options,
46-
node::options_parser::kDisallowedInEnvironment, &errors);
45+
options_parser.Parse(&args, &exec_args, &v8_args, &options,
46+
node::options_parser::kDisallowedInEnvironment, &errors);
4747

4848
if (!errors.empty()) {
4949
// TODO(jeremy): what's the appropriate behaviour here?
5050
LOG(ERROR) << "Error parsing node options: "
5151
<< base::JoinString(errors, " ");
5252
}
5353

54-
// Set process._debugWaitConnect if --inspect-brk was specified to stop
55-
// the debugger on the first line
56-
if (options.wait_for_connect()) {
57-
mate::Dictionary process(env_->isolate(), env_->process_object());
58-
process.Set("_breakFirstLine", true);
59-
}
60-
6154
const char* path = "";
6255
if (inspector->Start(path, options,
6356
std::make_shared<node::HostPort>(options.host_port),

atom/common/api/atom_api_asar.cc

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -117,16 +117,11 @@ class Archive : public mate::Wrappable<Archive> {
117117
DISALLOW_COPY_AND_ASSIGN(Archive);
118118
};
119119

120-
void InitAsarSupport(v8::Isolate* isolate,
121-
v8::Local<v8::Value> source,
122-
v8::Local<v8::Value> require) {
120+
void InitAsarSupport(v8::Isolate* isolate, v8::Local<v8::Value> require) {
123121
// Evaluate asar_init.js.
124122
std::vector<v8::Local<v8::String>> asar_init_params = {
125-
node::FIXED_ONE_BYTE_STRING(isolate, "source"),
126123
node::FIXED_ONE_BYTE_STRING(isolate, "require")};
127-
128-
std::vector<v8::Local<v8::Value>> asar_init_args = {source, require};
129-
124+
std::vector<v8::Local<v8::Value>> asar_init_args = {require};
130125
node::per_process::native_module_loader.CompileAndCall(
131126
isolate->GetCurrentContext(), "electron/js2c/asar_init",
132127
&asar_init_params, &asar_init_args, nullptr);

atom/common/node_includes.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@
2525
#pragma push_macro("CHECK_LE")
2626
#pragma push_macro("CHECK_LT")
2727
#pragma push_macro("CHECK_NE")
28+
#pragma push_macro("DCHECK")
29+
#pragma push_macro("DCHECK_EQ")
30+
#pragma push_macro("DCHECK_GE")
31+
#pragma push_macro("DCHECK_GT")
32+
#pragma push_macro("DCHECK_LE")
33+
#pragma push_macro("DCHECK_LT")
34+
#pragma push_macro("DCHECK_NE")
2835
#pragma push_macro("DISALLOW_COPY_AND_ASSIGN")
2936
#pragma push_macro("LIKELY")
3037
#pragma push_macro("NO_RETURN")
@@ -38,6 +45,13 @@
3845
#undef CHECK_LE
3946
#undef CHECK_LT
4047
#undef CHECK_NE
48+
#undef DCHECK
49+
#undef DCHECK_EQ
50+
#undef DCHECK_GE
51+
#undef DCHECK_GT
52+
#undef DCHECK_LE
53+
#undef DCHECK_LT
54+
#undef DCHECK_NE
4155
#undef DISALLOW_COPY_AND_ASSIGN
4256
#undef LIKELY
4357
#undef NO_RETURN
@@ -67,6 +81,13 @@
6781
#pragma pop_macro("CHECK_LE")
6882
#pragma pop_macro("CHECK_LT")
6983
#pragma pop_macro("CHECK_NE")
84+
#pragma pop_macro("DCHECK")
85+
#pragma pop_macro("DCHECK_EQ")
86+
#pragma pop_macro("DCHECK_GE")
87+
#pragma pop_macro("DCHECK_GT")
88+
#pragma pop_macro("DCHECK_LE")
89+
#pragma pop_macro("DCHECK_LT")
90+
#pragma pop_macro("DCHECK_NE")
7091
#pragma pop_macro("DISALLOW_COPY_AND_ASSIGN")
7192
#pragma pop_macro("LIKELY")
7293
#pragma pop_macro("NO_RETURN")

atom/renderer/api/atom_api_web_frame.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,9 @@ v8::Local<v8::Promise> ExecuteJavaScriptInIsolatedWorld(
372372
blink::WebLocalFrame::kSynchronous;
373373
args->GetNext(&scriptExecutionType);
374374

375+
// Debugging tip: if you see a crash stack trace beginning from this call,
376+
// then it is very likely that some exception happened when executing the
377+
// "content_script/init.js" script.
375378
GetRenderFrame(window)->GetWebFrame()->RequestExecuteScriptInIsolatedWorld(
376379
world_id, &sources.front(), sources.size(), has_user_gesture,
377380
scriptExecutionType, new ScriptExecutionCallback(std::move(promise)));

atom/renderer/atom_sandboxed_renderer_client.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ void AtomSandboxedRendererClient::SetupMainWorldOverrides(
245245
auto* isolate = context->GetIsolate();
246246

247247
mate::Dictionary process = mate::Dictionary::CreateEmpty(isolate);
248-
process.SetMethod("binding", GetBinding);
248+
process.SetMethod("_linkedBinding", GetBinding);
249249

250250
std::vector<v8::Local<v8::String>> isolated_bundle_params = {
251251
node::FIXED_ONE_BYTE_STRING(isolate, "nodeProcess"),
@@ -267,7 +267,7 @@ void AtomSandboxedRendererClient::SetupExtensionWorldOverrides(
267267
auto* isolate = context->GetIsolate();
268268

269269
mate::Dictionary process = mate::Dictionary::CreateEmpty(isolate);
270-
process.SetMethod("binding", GetBinding);
270+
process.SetMethod("_linkedBinding", GetBinding);
271271

272272
std::vector<v8::Local<v8::String>> isolated_bundle_params = {
273273
node::FIXED_ONE_BYTE_STRING(isolate, "nodeProcess"),

build/args/all.gn

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ is_electron_build = true
22
use_jumbo_build = true
33
root_extra_deps = [ "//electron" ]
44

5+
# Registry of NMVs --> https://github.com/nodejs/node/blob/master/doc/abi_version_registry.json
6+
node_module_version = 73
7+
58
v8_promise_internal_field_count = 1
69
v8_typed_array_max_size_in_heap = 0
710
v8_embedder_string = "-electron.0"

lib/common/asar.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
22

33
(function () {
4-
const asar = process.binding('atom_common_asar')
4+
const asar = process._linkedBinding('atom_common_asar')
55
const assert = require('assert')
66
const { Buffer } = require('buffer')
77
const childProcess = require('child_process')

lib/common/asar_init.js

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
11
'use strict'
22

3-
/* global source, require */
4-
5-
// Expose fs module without asar support.
6-
// NB: Node's 'fs' and 'internal/fs/streams' have a lazy-loaded circular
7-
// dependency. So to expose the unmodified Node 'fs' functionality here,
8-
// we have to copy both 'fs' *and* 'internal/fs/streams' and modify the
9-
// copies to depend on each other instead of on our asarified 'fs' code.
10-
source['original-fs'].replace("require('internal/fs/streams')", "require('original-fs/streams')")
11-
source['original-fs/streams'].replace("require('fs')", "require('original-fs')")
3+
/* global require */
124

135
// Monkey-patch the fs module.
146
require('electron/js2c/asar').wrapFsWithAsar(require('fs'))

lib/content_script/init.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
const { EventEmitter } = require('events')
66

7-
process.electronBinding = require('@electron/internal/common/atom-binding-setup').electronBindingSetup(nodeProcess.binding, 'renderer')
7+
process.electronBinding = require('@electron/internal/common/atom-binding-setup').electronBindingSetup(nodeProcess._linkedBinding, 'renderer')
88

99
const v8Util = process.electronBinding('v8_util')
1010

0 commit comments

Comments
 (0)