Skip to content

Commit

Permalink
src: use PER_ISOLATE_PUBLIC_SYMBOL_PROPERTIES to store the symbols
Browse files Browse the repository at this point in the history
Signed-off-by: Darshan Sen <darshan.sen@postman.com>
  • Loading branch information
RaisinTen committed Dec 17, 2021
1 parent d31188c commit 012d03b
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 11 deletions.
4 changes: 2 additions & 2 deletions lib/internal/per_context/domexception.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ const {
TypeError,
} = primordials;

const kClone = SymbolFor('nodejs.clone');
const kDeserialize = SymbolFor('nodejs.deserialize');
const kClone = SymbolFor('nodejs.worker_threads.clone');
const kDeserialize = SymbolFor('nodejs.worker_threads.deserialize');

class ERR_INVALID_THIS extends TypeError {
constructor(type) {
Expand Down
4 changes: 2 additions & 2 deletions lib/internal/worker/js_transferable.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ module.exports = {
makeTransferable,
setup,
JSTransferable,
kClone: SymbolFor('nodejs.clone'),
kDeserialize: SymbolFor('nodejs.deserialize'),
kClone: SymbolFor('nodejs.worker_threads.clone'),
kDeserialize: SymbolFor('nodejs.worker_threads.deserialize'),
kTransfer: messaging_transfer_symbol,
kTransferList: messaging_transfer_list_symbol,
};
9 changes: 9 additions & 0 deletions src/env-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -1263,6 +1263,14 @@ void Environment::set_process_exit_handler(
#undef VY
#undef VP

#define V(PropertyName, StringValue) \
inline v8::Local<v8::Symbol> IsolateData::PropertyName() const { \
return v8::Symbol::For(isolate_, FIXED_ONE_BYTE_STRING(isolate_, \
StringValue)); \
}
PER_ISOLATE_PUBLIC_SYMBOL_PROPERTIES(V)
#undef V

#define VP(PropertyName, StringValue) V(v8::Private, PropertyName)
#define VY(PropertyName, StringValue) V(v8::Symbol, PropertyName)
#define VS(PropertyName, StringValue) V(v8::String, PropertyName)
Expand All @@ -1272,6 +1280,7 @@ void Environment::set_process_exit_handler(
}
PER_ISOLATE_PRIVATE_SYMBOL_PROPERTIES(VP)
PER_ISOLATE_SYMBOL_PROPERTIES(VY)
PER_ISOLATE_PUBLIC_SYMBOL_PROPERTIES(VY)
PER_ISOLATE_STRING_PROPERTIES(VS)
#undef V
#undef VS
Expand Down
9 changes: 7 additions & 2 deletions src/env.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,11 @@ constexpr size_t kFsStatsBufferLength =
V(resource_symbol, "resource_symbol") \
V(trigger_async_id_symbol, "trigger_async_id_symbol") \

#define PER_ISOLATE_PUBLIC_SYMBOL_PROPERTIES(V) \
V(nodejs_worker_threads_clone_symbol, "nodejs.worker_threads.clone") \
V(nodejs_worker_threads_deserialize_symbol, \
"nodejs.worker_threads.deserialize") \

// Strings are per-isolate primitives but Environment proxies them
// for the sake of convenience. Strings should be ASCII-only.
#define PER_ISOLATE_STRING_PROPERTIES(V) \
Expand Down Expand Up @@ -329,8 +334,6 @@ constexpr size_t kFsStatsBufferLength =
V(next_string, "next") \
V(nistcurve_string, "nistCurve") \
V(node_string, "node") \
V(nodejs_clone_string, "nodejs.clone") \
V(nodejs_deserialize_string, "nodejs.deserialize") \
V(nsname_string, "nsname") \
V(ocsp_request_string, "OCSPRequest") \
V(oncertcb_string, "oncertcb") \
Expand Down Expand Up @@ -583,6 +586,7 @@ class IsolateData : public MemoryRetainer {
inline v8::Local<TypeName> PropertyName() const;
PER_ISOLATE_PRIVATE_SYMBOL_PROPERTIES(VP)
PER_ISOLATE_SYMBOL_PROPERTIES(VY)
PER_ISOLATE_PUBLIC_SYMBOL_PROPERTIES(VY)
PER_ISOLATE_STRING_PROPERTIES(VS)
#undef V
#undef VY
Expand Down Expand Up @@ -1306,6 +1310,7 @@ class Environment : public MemoryRetainer {
inline v8::Local<TypeName> PropertyName() const;
PER_ISOLATE_PRIVATE_SYMBOL_PROPERTIES(VP)
PER_ISOLATE_SYMBOL_PROPERTIES(VY)
PER_ISOLATE_PUBLIC_SYMBOL_PROPERTIES(VY)
PER_ISOLATE_STRING_PROPERTIES(VS)
#undef V
#undef VS
Expand Down
8 changes: 3 additions & 5 deletions src/node_messaging.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1171,8 +1171,7 @@ JSTransferable::TransferMode JSTransferable::GetTransferMode() const {

bool has_clone;
if (!object()->Has(env()->context(),
Symbol::For(env()->isolate(),
env()->nodejs_clone_string())).To(&has_clone)) {
env()->nodejs_worker_threads_clone_symbol()).To(&has_clone)) {
return TransferMode::kUntransferable;
}

Expand All @@ -1196,7 +1195,7 @@ std::unique_ptr<TransferData> JSTransferable::TransferOrClone(
HandleScope handle_scope(env()->isolate());
Local<Context> context = env()->isolate()->GetCurrentContext();
Local<Symbol> method_name = mode == TransferMode::kCloneable ?
Symbol::For(env()->isolate(), env()->nodejs_clone_string()) :
env()->nodejs_worker_threads_clone_symbol() :
env()->messaging_transfer_symbol();

Local<Value> method;
Expand Down Expand Up @@ -1272,8 +1271,7 @@ Maybe<bool> JSTransferable::FinalizeTransferRead(
Local<Value> data;
if (!deserializer->ReadValue(context).ToLocal(&data)) return Nothing<bool>();

Local<Symbol> method_name = Symbol::For(env()->isolate(),
env()->nodejs_deserialize_string());
Local<Symbol> method_name = env()->nodejs_worker_threads_deserialize_symbol();
Local<Value> method;
if (!object()->Get(context, method_name).ToLocal(&method)) {
return Nothing<bool>();
Expand Down

0 comments on commit 012d03b

Please sign in to comment.