| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 3117899 commit 89e4b36
5 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -39,15 +39,13 @@ using v8::NewStringType; | |||
| 39 | 39 | using v8::Number; | |
| 40 | 40 | using v8::Object; | |
| 41 | 41 | using v8::Private; | |
| 42 | - using v8::ScriptOrModule; | ||
| 43 | 42 | using v8::SnapshotCreator; | |
| 44 | 43 | using v8::StackTrace; | |
| 45 | 44 | using v8::String; | |
| 46 | 45 | using v8::Symbol; | |
| 47 | 46 | using v8::TracingController; | |
| 48 | 47 | using v8::Undefined; | |
| 49 | 48 | using v8::Value; | |
| 50 | - using v8::WeakCallbackInfo; | ||
| 51 | 49 | using worker::Worker; | |
| 52 | 50 | ||
| 53 | 51 | int const Environment::kNodeContextTag = 0x6e6f64; | |
@@ -387,24 +385,6 @@ Environment::Environment(IsolateData* isolate_data, | |||
| 387 | 385 | CreateProperties(); | |
| 388 | 386 | } | |
| 389 | 387 | ||
| 390 | - static void WeakCallbackCompiledFn( | ||
| 391 | - const WeakCallbackInfo<CompiledFnEntry>& data) { | ||
| 392 | - CompiledFnEntry* entry = data.GetParameter(); | ||
| 393 | - entry->env->id_to_function_map.erase(entry->id); | ||
| 394 | - delete entry; | ||
| 395 | - } | ||
| 396 | - | ||
| 397 | - CompiledFnEntry::CompiledFnEntry(Environment* env, | ||
| 398 | - uint32_t id, | ||
| 399 | - Local<ScriptOrModule> script) | ||
| 400 | - : env(env), | ||
| 401 | - id(id), | ||
| 402 | - cache_key(env->isolate(), Object::New(env->isolate())), | ||
| 403 | - script(env->isolate(), script) { | ||
| 404 | - this->script.SetWeak( | ||
| 405 | - this, WeakCallbackCompiledFn, v8::WeakCallbackType::kParameter); | ||
| 406 | - } | ||
| 407 | - | ||
| 408 | 388 | Environment::~Environment() { | |
| 409 | 389 | isolate()->GetHeapProfiler()->RemoveBuildEmbedderGraphCallback( | |
| 410 | 390 | BuildEmbedderGraph, this); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -55,6 +55,7 @@ namespace node { | |||
| 55 | 55 | ||
| 56 | 56 | namespace contextify { | |
| 57 | 57 | class ContextifyScript; | |
| 58 | + class CompiledFnEntry; | ||
| 58 | 59 | } | |
| 59 | 60 | ||
| 60 | 61 | namespace fs { | |
@@ -377,6 +378,7 @@ constexpr size_t kFsStatsBufferLength = | |||
| 377 | 378 | V(as_callback_data_template, v8::FunctionTemplate) \ | |
| 378 | 379 | V(async_wrap_ctor_template, v8::FunctionTemplate) \ | |
| 379 | 380 | V(async_wrap_object_ctor_template, v8::FunctionTemplate) \ | |
| 381 | + V(compiled_fn_entry_template, v8::ObjectTemplate) \ | ||
| 380 | 382 | V(fd_constructor_template, v8::ObjectTemplate) \ | |
| 381 | 383 | V(fdclose_constructor_template, v8::ObjectTemplate) \ | |
| 382 | 384 | V(filehandlereadwrap_template, v8::ObjectTemplate) \ | |
@@ -523,16 +525,6 @@ struct ContextInfo { | |||
| 523 | 525 | bool is_default = false; | |
| 524 | 526 | }; | |
| 525 | 527 | ||
| 526 | - struct CompiledFnEntry { | ||
| 527 | - Environment* env; | ||
| 528 | - uint32_t id; | ||
| 529 | - v8::Global<v8::Object> cache_key; | ||
| 530 | - v8::Global<v8::ScriptOrModule> script; | ||
| 531 | - CompiledFnEntry(Environment* env, | ||
| 532 | - uint32_t id, | ||
| 533 | - v8::Local<v8::ScriptOrModule> script); | ||
| 534 | - }; | ||
| 535 | - | ||
| 536 | 528 | // Listing the AsyncWrap provider types first enables us to cast directly | |
| 537 | 529 | // from a provider type to a debug category. | |
| 538 | 530 | #define DEBUG_CATEGORY_NAMES(V) \ | |
@@ -1017,7 +1009,7 @@ class Environment : public MemoryRetainer { | |||
| 1017 | 1009 | std::unordered_map<uint32_t, loader::ModuleWrap*> id_to_module_map; | |
| 1018 | 1010 | std::unordered_map<uint32_t, contextify::ContextifyScript*> | |
| 1019 | 1011 | id_to_script_map; | |
| 1020 | - std::unordered_map<uint32_t, CompiledFnEntry*> id_to_function_map; | ||
| 1012 | + std::unordered_map<uint32_t, contextify::CompiledFnEntry*> id_to_function_map; | ||
| 1021 | 1013 | ||
| 1022 | 1014 | inline uint32_t get_next_module_id(); | |
| 1023 | 1015 | inline uint32_t get_next_script_id(); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1041,7 +1041,9 @@ static MaybeLocal<Promise> ImportModuleDynamically( | |||
| 1041 | 1041 | ModuleWrap* wrap = ModuleWrap::GetFromID(env, id); | |
| 1042 | 1042 | object = wrap->object(); | |
| 1043 | 1043 | } else if (type == ScriptType::kFunction) { | |
| 1044 | - object = env->id_to_function_map.find(id)->second->cache_key.Get(iso); | ||
| 1044 | + auto it = env->id_to_function_map.find(id); | ||
| 1045 | + CHECK_NE(it, env->id_to_function_map.end()); | ||
| 1046 | + object = it->second->object(); | ||
| 1045 | 1047 | } else { | |
| 1046 | 1048 | UNREACHABLE(); | |
| 1047 | 1049 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1124,9 +1124,13 @@ void ContextifyContext::CompileFunction( | |||
| 1124 | 1124 | } | |
| 1125 | 1125 | Local<Function> fn = maybe_fn.ToLocalChecked(); | |
| 1126 | 1126 | ||
| 1127 | - CompiledFnEntry* entry = new CompiledFnEntry(env, id, script); | ||
| 1127 | + Local<Object> cache_key; | ||
| 1128 | + if (!env->compiled_fn_entry_template()->NewInstance( | ||
| 1129 | + context).ToLocal(&cache_key)) { | ||
| 1130 | + return; | ||
| 1131 | + } | ||
| 1132 | + CompiledFnEntry* entry = new CompiledFnEntry(env, cache_key, id, script); | ||
| 1128 | 1133 | env->id_to_function_map.emplace(id, entry); | |
| 1129 | - Local<Object> cache_key = entry->cache_key.Get(isolate); | ||
| 1130 | 1134 | ||
| 1131 | 1135 | Local<Object> result = Object::New(isolate); | |
| 1132 | 1136 | if (result->Set(parsing_context, env->function_string(), fn).IsNothing()) | |
@@ -1162,6 +1166,27 @@ void ContextifyContext::CompileFunction( | |||
| 1162 | 1166 | args.GetReturnValue().Set(result); | |
| 1163 | 1167 | } | |
| 1164 | 1168 | ||
| 1169 | + void CompiledFnEntry::WeakCallback( | ||
| 1170 | + const WeakCallbackInfo<CompiledFnEntry>& data) { | ||
| 1171 | + CompiledFnEntry* entry = data.GetParameter(); | ||
| 1172 | + delete entry; | ||
| 1173 | + } | ||
| 1174 | + | ||
| 1175 | + CompiledFnEntry::CompiledFnEntry(Environment* env, | ||
| 1176 | + Local<Object> object, | ||
| 1177 | + uint32_t id, | ||
| 1178 | + Local<ScriptOrModule> script) | ||
| 1179 | + : BaseObject(env, object), | ||
| 1180 | + id_(id), | ||
| 1181 | + script_(env->isolate(), script) { | ||
| 1182 | + script_.SetWeak(this, WeakCallback, v8::WeakCallbackType::kParameter); | ||
| 1183 | + } | ||
| 1184 | + | ||
| 1185 | + CompiledFnEntry::~CompiledFnEntry() { | ||
| 1186 | + env()->id_to_function_map.erase(id_); | ||
| 1187 | + script_.ClearWeak(); | ||
| 1188 | + } | ||
| 1189 | + | ||
| 1165 | 1190 | static void StartSigintWatchdog(const FunctionCallbackInfo<Value>& args) { | |
| 1166 | 1191 | int ret = SigintWatchdogHelper::GetInstance()->Start(); | |
| 1167 | 1192 | args.GetReturnValue().Set(ret == 0); | |
@@ -1190,6 +1215,14 @@ void Initialize(Local<Object> target, | |||
| 1190 | 1215 | // Used in tests. | |
| 1191 | 1216 | env->SetMethodNoSideEffect( | |
| 1192 | 1217 | target, "watchdogHasPendingSigint", WatchdogHasPendingSigint); | |
| 1218 | + | ||
| 1219 | + { | ||
| 1220 | + Local<FunctionTemplate> tpl = FunctionTemplate::New(env->isolate()); | ||
| 1221 | + tpl->SetClassName(FIXED_ONE_BYTE_STRING(env->isolate(), "CompiledFnEntry")); | ||
| 1222 | + tpl->InstanceTemplate()->SetInternalFieldCount(1); | ||
| 1223 | + | ||
| 1224 | + env->set_compiled_fn_entry_template(tpl->InstanceTemplate()); | ||
| 1225 | + } | ||
| 1193 | 1226 | } | |
| 1194 | 1227 | ||
| 1195 | 1228 | } // namespace contextify | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -133,6 +133,25 @@ class ContextifyScript : public BaseObject { | |||
| 133 | 133 | uint32_t id_; | |
| 134 | 134 | }; | |
| 135 | 135 | ||
| 136 | + class CompiledFnEntry final : public BaseObject { | ||
| 137 | + public: | ||
| 138 | + SET_NO_MEMORY_INFO() | ||
| 139 | + SET_MEMORY_INFO_NAME(CompiledFnEntry) | ||
| 140 | + SET_SELF_SIZE(CompiledFnEntry) | ||
| 141 | + | ||
| 142 | + CompiledFnEntry(Environment* env, | ||
| 143 | + v8::Local<v8::Object> object, | ||
| 144 | + uint32_t id, | ||
| 145 | + v8::Local<v8::ScriptOrModule> script); | ||
| 146 | + ~CompiledFnEntry(); | ||
| 147 | + | ||
| 148 | + private: | ||
| 149 | + uint32_t id_; | ||
| 150 | + v8::Global<v8::ScriptOrModule> script_; | ||
| 151 | + | ||
| 152 | + static void WeakCallback(const v8::WeakCallbackInfo<CompiledFnEntry>& data); | ||
| 153 | + }; | ||
| 154 | + | ||
| 136 | 155 | } // namespace contextify | |
| 137 | 156 | } // namespace node | |
| 138 | 157 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments