| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 6187e81 commit 250e197
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -94,7 +94,7 @@ v8::Local<v8::Array> AsyncHooks::js_execution_async_resources() { | |||
| 94 | 94 | ||
| 95 | 95 | v8::Local<v8::Object> AsyncHooks::native_execution_async_resource(size_t i) { | |
| 96 | 96 | if (i >= native_execution_async_resources_.size()) return {}; | |
| 97 | - return PersistentToLocal::Strong(native_execution_async_resources_[i]); | ||
| 97 | + return native_execution_async_resources_[i]; | ||
| 98 | 98 | } | |
| 99 | 99 | ||
| 100 | 100 | inline void AsyncHooks::SetJSPromiseHooks(v8::Local<v8::Function> init, | |
@@ -154,12 +154,11 @@ inline void AsyncHooks::push_async_context(double async_id, | |||
| 154 | 154 | #endif | |
| 155 | 155 | ||
| 156 | 156 | // When this call comes from JS (as a way of increasing the stack size), | |
| 157 | - // `resource` will be empty, because JS caches these values anyway, and | ||
| 158 | - // we should avoid creating strong global references that might keep | ||
| 159 | - // these JS resource objects alive longer than necessary. | ||
| 157 | + // `resource` will be empty, because JS caches these values anyway. | ||
| 160 | 158 | if (!resource.IsEmpty()) { | |
| 161 | 159 | native_execution_async_resources_.resize(offset + 1); | |
| 162 | - native_execution_async_resources_[offset].Reset(env()->isolate(), resource); | ||
| 160 | + // Caveat: This is a v8::Local<> assignment, we do not keep a v8::Global<>! | ||
| 161 | + native_execution_async_resources_[offset] = resource; | ||
| 163 | 162 | } | |
| 164 | 163 | } | |
| 165 | 164 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1096,20 +1096,29 @@ void AsyncHooks::Deserialize(Local<Context> context) { | |||
| 1096 | 1096 | async_ids_stack_.Deserialize(context); | |
| 1097 | 1097 | fields_.Deserialize(context); | |
| 1098 | 1098 | async_id_fields_.Deserialize(context); | |
| 1099 | + | ||
| 1100 | + Local<Array> js_execution_async_resources; | ||
| 1099 | 1101 | if (info_->js_execution_async_resources != 0) { | |
| 1100 | - Local<Array> arr = context->GetDataFromSnapshotOnce<Array>( | ||
| 1101 | - info_->js_execution_async_resources) | ||
| 1102 | - .ToLocalChecked(); | ||
| 1103 | - js_execution_async_resources_.Reset(context->GetIsolate(), arr); | ||
| 1102 | + js_execution_async_resources = | ||
| 1103 | + context->GetDataFromSnapshotOnce<Array>( | ||
| 1104 | + info_->js_execution_async_resources).ToLocalChecked(); | ||
| 1105 | + } else { | ||
| 1106 | + js_execution_async_resources = Array::New(context->GetIsolate()); | ||
| 1104 | 1107 | } | |
| 1108 | + js_execution_async_resources_.Reset( | ||
| 1109 | + context->GetIsolate(), js_execution_async_resources); | ||
| 1105 | 1110 | ||
| 1106 | - native_execution_async_resources_.resize( | ||
| 1107 | - info_->native_execution_async_resources.size()); | ||
| 1111 | + // The native_execution_async_resources_ field requires v8::Local<> instances | ||
| 1112 | + // for async calls whose resources were on the stack as JS objects when they | ||
| 1113 | + // were entered. We cannot recreate this here; however, storing these values | ||
| 1114 | + // on the JS equivalent gives the same result, so we do that instead. | ||
| 1108 | 1115 | for (size_t i = 0; i < info_->native_execution_async_resources.size(); ++i) { | |
| 1116 | + if (info_->native_execution_async_resources[i] == SIZE_MAX) | ||
| 1117 | + continue; | ||
| 1109 | 1118 | Local<Object> obj = context->GetDataFromSnapshotOnce<Object>( | |
| 1110 | 1119 | info_->native_execution_async_resources[i]) | |
| 1111 | 1120 | .ToLocalChecked(); | |
| 1112 | - native_execution_async_resources_[i].Reset(context->GetIsolate(), obj); | ||
| 1121 | + js_execution_async_resources->Set(context, i, obj).Check(); | ||
| 1113 | 1122 | } | |
| 1114 | 1123 | info_ = nullptr; | |
| 1115 | 1124 | } | |
@@ -1155,9 +1164,11 @@ AsyncHooks::SerializeInfo AsyncHooks::Serialize(Local<Context> context, | |||
| 1155 | 1164 | info.native_execution_async_resources.resize( | |
| 1156 | 1165 | native_execution_async_resources_.size()); | |
| 1157 | 1166 | for (size_t i = 0; i < native_execution_async_resources_.size(); i++) { | |
| 1158 | - info.native_execution_async_resources[i] = creator->AddData( | ||
| 1159 | - context, | ||
| 1160 | - native_execution_async_resources_[i].Get(context->GetIsolate())); | ||
| 1167 | + info.native_execution_async_resources[i] = | ||
| 1168 | + native_execution_async_resources_[i].IsEmpty() ? SIZE_MAX : | ||
| 1169 | + creator->AddData( | ||
| 1170 | + context, | ||
| 1171 | + native_execution_async_resources_[i]); | ||
| 1161 | 1172 | } | |
| 1162 | 1173 | CHECK_EQ(contexts_.size(), 1); | |
| 1163 | 1174 | CHECK_EQ(contexts_[0], env()->context()); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -719,8 +719,11 @@ class AsyncHooks : public MemoryRetainer { | |||
| 719 | 719 | inline void no_force_checks(); | |
| 720 | 720 | inline Environment* env(); | |
| 721 | 721 | ||
| 722 | + // NB: This call does not take (co-)ownership of `execution_async_resource`. | ||
| 723 | + // The lifetime of the `v8::Local<>` pointee must last until | ||
| 724 | + // `pop_async_context()` or `clear_async_id_stack()` are called. | ||
| 722 | 725 | inline void push_async_context(double async_id, double trigger_async_id, | |
| 723 | - v8::Local<v8::Object> execution_async_resource_); | ||
| 726 | + v8::Local<v8::Object> execution_async_resource); | ||
| 724 | 727 | inline bool pop_async_context(double async_id); | |
| 725 | 728 | inline void clear_async_id_stack(); // Used in fatal exceptions. | |
| 726 | 729 | ||
@@ -782,7 +785,7 @@ class AsyncHooks : public MemoryRetainer { | |||
| 782 | 785 | void grow_async_ids_stack(); | |
| 783 | 786 | ||
| 784 | 787 | v8::Global<v8::Array> js_execution_async_resources_; | |
| 785 | - std::vector<v8::Global<v8::Object>> native_execution_async_resources_; | ||
| 788 | + std::vector<v8::Local<v8::Object>> native_execution_async_resources_; | ||
| 786 | 789 | ||
| 787 | 790 | // Non-empty during deserialization | |
| 788 | 791 | const SerializeInfo* info_ = nullptr; | |
| Back | FazBrowse Home | New Git URL |
0 commit comments