Skip to content

Commit fc89994

Browse files
authored
Don't use soon-to-be-deprecated V8 Api (#179)
V8 announced deprecation of the following methods: - v8::Objecit::SetAccessor(...) in favor of v8::Object::SetNativeDataProperty(...), - v8::ObjectTemplate::SetNativeDataProperty(...) with AccessControl parameter in favor of v8::ObjectTemplate::SetNativeDataProperty(...) without AccessControl parameter. See https://crrev.com/c/5006387. This CL slightly changes behavior of the following properties: - process.debugPort (for worker processes), - process.title (for worker processes), - process.ppid. The difference is that they will now behave like a regular writable JavaScript data properties - in case setter callback is not provided they will be be reconfigured from a native data property (the one that calls C++ callbacks upon get/set operations) to a real data property (so subsequent reads will no longer trigger C++ getter callbacks).
1 parent 776b330 commit fc89994

File tree

3 files changed

+24
-20
lines changed

3 files changed

+24
-20
lines changed

src/node_builtins.cc

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ namespace node {
1111
namespace builtins {
1212

1313
using v8::Context;
14-
using v8::DEFAULT;
1514
using v8::EscapableHandleScope;
1615
using v8::Function;
1716
using v8::FunctionCallbackInfo;
@@ -711,15 +710,13 @@ void BuiltinLoader::CreatePerIsolateProperties(IsolateData* isolate_data,
711710
nullptr,
712711
Local<Value>(),
713712
None,
714-
DEFAULT,
715713
SideEffectType::kHasNoSideEffect);
716714

717715
target->SetNativeDataProperty(FIXED_ONE_BYTE_STRING(isolate, "builtinIds"),
718716
BuiltinIdsGetter,
719717
nullptr,
720718
Local<Value>(),
721719
None,
722-
DEFAULT,
723720
SideEffectType::kHasNoSideEffect);
724721

725722
target->SetNativeDataProperty(
@@ -728,15 +725,13 @@ void BuiltinLoader::CreatePerIsolateProperties(IsolateData* isolate_data,
728725
nullptr,
729726
Local<Value>(),
730727
None,
731-
DEFAULT,
732728
SideEffectType::kHasNoSideEffect);
733729

734730
target->SetNativeDataProperty(FIXED_ONE_BYTE_STRING(isolate, "natives"),
735731
GetNatives,
736732
nullptr,
737733
Local<Value>(),
738734
None,
739-
DEFAULT,
740735
SideEffectType::kHasNoSideEffect);
741736

742737
SetMethod(isolate, target, "getCacheUsage", BuiltinLoader::GetCacheUsage);

src/node_process_object.cc

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
namespace node {
1515
using v8::Context;
16-
using v8::DEFAULT;
1716
using v8::EscapableHandleScope;
1817
using v8::Function;
1918
using v8::FunctionCallbackInfo;
@@ -183,13 +182,12 @@ void PatchProcessObject(const FunctionCallbackInfo<Value>& args) {
183182

184183
// process.title
185184
CHECK(process
186-
->SetAccessor(
185+
->SetNativeDataProperty(
187186
context,
188187
FIXED_ONE_BYTE_STRING(isolate, "title"),
189188
ProcessTitleGetter,
190189
env->owns_process_state() ? ProcessTitleSetter : nullptr,
191190
Local<Value>(),
192-
DEFAULT,
193191
None,
194192
SideEffectType::kHasNoSideEffect)
195193
.FromJust());
@@ -208,9 +206,15 @@ void PatchProcessObject(const FunctionCallbackInfo<Value>& args) {
208206
READONLY_PROPERTY(process, "pid",
209207
Integer::New(isolate, uv_os_getpid()));
210208

211-
CHECK(process->SetAccessor(context,
212-
FIXED_ONE_BYTE_STRING(isolate, "ppid"),
213-
GetParentProcessId).FromJust());
209+
CHECK(process
210+
->SetNativeDataProperty(context,
211+
FIXED_ONE_BYTE_STRING(isolate, "ppid"),
212+
GetParentProcessId,
213+
nullptr,
214+
Local<Value>(),
215+
None,
216+
SideEffectType::kHasNoSideEffect)
217+
.FromJust());
214218

215219
// --security-revert flags
216220
#define V(code, _, __) \
@@ -235,11 +239,14 @@ void PatchProcessObject(const FunctionCallbackInfo<Value>& args) {
235239

236240
// process.debugPort
237241
CHECK(process
238-
->SetAccessor(context,
239-
FIXED_ONE_BYTE_STRING(isolate, "debugPort"),
240-
DebugPortGetter,
241-
env->owns_process_state() ? DebugPortSetter : nullptr,
242-
Local<Value>())
242+
->SetNativeDataProperty(
243+
context,
244+
FIXED_ONE_BYTE_STRING(isolate, "debugPort"),
245+
DebugPortGetter,
246+
env->owns_process_state() ? DebugPortSetter : nullptr,
247+
Local<Value>(),
248+
None,
249+
SideEffectType::kHasNoSideEffect)
243250
.FromJust());
244251
}
245252

test/parallel/test-worker-unsupported-things.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,16 @@ if (!process.env.HAS_STARTED_WORKER) {
1414
} else {
1515
{
1616
const before = process.title;
17-
process.title += ' in worker';
18-
assert.strictEqual(process.title, before);
17+
const after = before + ' in worker';
18+
process.title = after;
19+
assert.strictEqual(process.title, after);
1920
}
2021

2122
{
2223
const before = process.debugPort;
23-
process.debugPort++;
24-
assert.strictEqual(process.debugPort, before);
24+
const after = before + 1;
25+
process.debugPort = after;
26+
assert.strictEqual(process.debugPort, after);
2527
}
2628

2729
{

0 commit comments

Comments
 (0)