| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 578a2c5 commit 77b4aca
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -20,6 +20,7 @@ | |||
| 20 | 20 | #define PER_ISOLATE_PRIVATE_SYMBOL_PROPERTIES(V) \ | |
| 21 | 21 | V(arrow_message_private_symbol, "node:arrowMessage") \ | |
| 22 | 22 | V(contextify_context_private_symbol, "node:contextify:context") \ | |
| 23 | + V(compiled_function_entry, "node:compiled_function_entry") \ | ||
| 23 | 24 | V(decorated_private_symbol, "node:decorated") \ | |
| 24 | 25 | V(napi_type_tag, "node:napi:type_tag") \ | |
| 25 | 26 | V(napi_wrapper, "node:napi:wrapper") \ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -77,7 +77,6 @@ using v8::Uint32; | |||
| 77 | 77 | using v8::UnboundScript; | |
| 78 | 78 | using v8::Value; | |
| 79 | 79 | using v8::WeakCallbackInfo; | |
| 80 | - using v8::WeakCallbackType; | ||
| 81 | 80 | ||
| 82 | 81 | // The vm module executes code in a sandboxed environment with a different | |
| 83 | 82 | // global object than the rest of the code. This is achieved by applying | |
@@ -1263,8 +1262,7 @@ void ContextifyContext::CompileFunction( | |||
| 1263 | 1262 | context).ToLocal(&cache_key)) { | |
| 1264 | 1263 | return; | |
| 1265 | 1264 | } | |
| 1266 | - CompiledFnEntry* entry = new CompiledFnEntry(env, cache_key, id, fn); | ||
| 1267 | - env->id_to_function_map.emplace(id, entry); | ||
| 1265 | + new CompiledFnEntry(env, cache_key, id, fn); | ||
| 1268 | 1266 | ||
| 1269 | 1267 | Local<Object> result = Object::New(isolate); | |
| 1270 | 1268 | if (result->Set(parsing_context, env->function_string(), fn).IsNothing()) | |
@@ -1296,23 +1294,18 @@ void ContextifyContext::CompileFunction( | |||
| 1296 | 1294 | args.GetReturnValue().Set(result); | |
| 1297 | 1295 | } | |
| 1298 | 1296 | ||
| 1299 | - void CompiledFnEntry::WeakCallback( | ||
| 1300 | - const WeakCallbackInfo<CompiledFnEntry>& data) { | ||
| 1301 | - CompiledFnEntry* entry = data.GetParameter(); | ||
| 1302 | - delete entry; | ||
| 1303 | - } | ||
| 1304 | - | ||
| 1305 | 1297 | CompiledFnEntry::CompiledFnEntry(Environment* env, | |
| 1306 | 1298 | Local<Object> object, | |
| 1307 | 1299 | uint32_t id, | |
| 1308 | 1300 | Local<Function> fn) | |
| 1309 | - : BaseObject(env, object), id_(id), fn_(env->isolate(), fn) { | ||
| 1310 | - fn_.SetWeak(this, WeakCallback, v8::WeakCallbackType::kParameter); | ||
| 1301 | + : BaseObject(env, object), id_(id) { | ||
| 1302 | + MakeWeak(); | ||
| 1303 | + fn->SetPrivate(env->context(), env->compiled_function_entry(), object); | ||
| 1304 | + env->id_to_function_map.emplace(id, this); | ||
| 1311 | 1305 | } | |
| 1312 | 1306 | ||
| 1313 | 1307 | CompiledFnEntry::~CompiledFnEntry() { | |
| 1314 | 1308 | env()->id_to_function_map.erase(id_); | |
| 1315 | - fn_.ClearWeak(); | ||
| 1316 | 1309 | } | |
| 1317 | 1310 | ||
| 1318 | 1311 | static void StartSigintWatchdog(const FunctionCallbackInfo<Value>& args) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -194,9 +194,6 @@ class CompiledFnEntry final : public BaseObject { | |||
| 194 | 194 | ||
| 195 | 195 | private: | |
| 196 | 196 | uint32_t id_; | |
| 197 | - v8::Global<v8::Function> fn_; | ||
| 198 | - | ||
| 199 | - static void WeakCallback(const v8::WeakCallbackInfo<CompiledFnEntry>& data); | ||
| 200 | 197 | }; | |
| 201 | 198 | ||
| 202 | 199 | v8::Maybe<bool> StoreCodeCacheResult( | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,14 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + | ||
| 3 | + // Flags: --max-old-space-size=10 | ||
| 4 | + | ||
| 5 | + require('../common'); | ||
| 6 | + const vm = require('vm'); | ||
| 7 | + | ||
| 8 | + const code = `console.log("${'hello world '.repeat(1e5)}");`; | ||
| 9 | + | ||
| 10 | + for (let i = 0; i < 10000; i++) { | ||
| 11 | + vm.compileFunction(code, [], { | ||
| 12 | + importModuleDynamically: () => {}, | ||
| 13 | + }); | ||
| 14 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments