Skip to content

Commit

Permalink
src: split property helpers from node::Environment
Browse files Browse the repository at this point in the history
  • Loading branch information
codebytere committed Nov 8, 2022
1 parent 9706bd6 commit 23e04ca
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
1 change: 1 addition & 0 deletions patches/node/.patches
Expand Up @@ -49,3 +49,4 @@ test_remove_experimental-wasm-threads_flag.patch
api_pass_oomdetails_to_oomerrorcallback.patch
src_iwyu_in_cleanup_queue_cc.patch
fix_expose_lookupandcompile_with_parameters.patch
fix_prevent_changing_functiontemplateinfo_after_publish.patch
@@ -0,0 +1,61 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Shelley Vohr <shelley.vohr@gmail.com>
Date: Sun, 23 Oct 2022 23:36:19 +0200
Subject: fix: prevent changing FunctionTemplateInfo after publish

Refs https://chromium-review.googlesource.com/c/v8/v8/+/2718147

Fixes an issue where Node.js would try to call SetClassName on a
FunctionTemplate twice in some cases. The above CL made it so that
V8 CHECKs when this occurs. It is fixed by ensuring SetClassName
is only called once.

This should be upstreamed.

diff --git a/src/histogram.cc b/src/histogram.cc
index 3a3228ddc9eb6b53efc0721466479a9f62cd8967..175a67840348ca507d6e8b29835e5ab3b6d3e71a 100644
--- a/src/histogram.cc
+++ b/src/histogram.cc
@@ -340,8 +340,9 @@ void HistogramBase::RegisterExternalReferences(
}

void HistogramBase::Initialize(Environment* env, Local<Object> target) {
- SetConstructorFunction(
- env->context(), target, "Histogram", GetConstructorTemplate(env));
+ SetConstructorFunction(env->context(), target, "Histogram",
+ GetConstructorTemplate(env),
+ SetConstructorFunctionFlag::NONE);
}

BaseObjectPtr<BaseObject> HistogramBase::HistogramTransferData::Deserialize(
@@ -367,6 +368,7 @@ Local<FunctionTemplate> IntervalHistogram::GetConstructorTemplate(
Isolate* isolate = env->isolate();
tmpl = NewFunctionTemplate(isolate, nullptr);
tmpl->Inherit(HandleWrap::GetConstructorTemplate(env));
+ tmpl->SetClassName(OneByteString(isolate, "Histogram"));
tmpl->InstanceTemplate()->SetInternalFieldCount(
HistogramBase::kInternalFieldCount);
SetProtoMethodNoSideEffect(isolate, tmpl, "count", GetCount);
diff --git a/src/node_messaging.cc b/src/node_messaging.cc
index f88270fc75de91610a973c0649e1bc699c3e014d..e47f7a597a6ca0cfd71fec1e42f0fbb75cb539c7 100644
--- a/src/node_messaging.cc
+++ b/src/node_messaging.cc
@@ -1467,13 +1467,16 @@ static void InitMessaging(Local<Object> target,
t->Inherit(BaseObject::GetConstructorTemplate(env));
t->InstanceTemplate()->SetInternalFieldCount(
JSTransferable::kInternalFieldCount);
- SetConstructorFunction(context, target, "JSTransferable", t);
+ t->SetClassName(OneByteString(isolate, "JSTransferable"));
+ SetConstructorFunction(context, target, "JSTransferable", t,
+ SetConstructorFunctionFlag::NONE);
}

SetConstructorFunction(context,
target,
env->message_port_constructor_string(),
- GetMessagePortConstructorTemplate(env));
+ GetMessagePortConstructorTemplate(env),
+ SetConstructorFunctionFlag::NONE);

// These are not methods on the MessagePort prototype, because
// the browser equivalents do not provide them.

0 comments on commit 23e04ca

Please sign in to comment.