| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 050efeb commit a0df91c
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -196,36 +196,56 @@ void SetIsolateCreateParamsForNode(Isolate::CreateParams* params) { | |||
| 196 | 196 | } | |
| 197 | 197 | } | |
| 198 | 198 | ||
| 199 | - void SetIsolateUpForNode(v8::Isolate* isolate, IsolateSettingCategories cat) { | ||
| 200 | - switch (cat) { | ||
| 201 | - case IsolateSettingCategories::kErrorHandlers: | ||
| 202 | - isolate->AddMessageListenerWithErrorLevel( | ||
| 203 | - errors::PerIsolateMessageListener, | ||
| 204 | - Isolate::MessageErrorLevel::kMessageError | | ||
| 205 | - Isolate::MessageErrorLevel::kMessageWarning); | ||
| 206 | - isolate->SetAbortOnUncaughtExceptionCallback( | ||
| 207 | - ShouldAbortOnUncaughtException); | ||
| 208 | - isolate->SetFatalErrorHandler(OnFatalError); | ||
| 209 | - isolate->SetPrepareStackTraceCallback(PrepareStackTraceCallback); | ||
| 210 | - break; | ||
| 211 | - case IsolateSettingCategories::kMisc: | ||
| 212 | - isolate->SetMicrotasksPolicy(MicrotasksPolicy::kExplicit); | ||
| 213 | - isolate->SetAllowWasmCodeGenerationCallback( | ||
| 214 | - AllowWasmCodeGenerationCallback); | ||
| 215 | - isolate->SetPromiseRejectCallback(task_queue::PromiseRejectCallback); | ||
| 216 | - isolate->SetHostCleanupFinalizationGroupCallback( | ||
| 217 | - HostCleanupFinalizationGroupCallback); | ||
| 218 | - v8::CpuProfiler::UseDetailedSourcePositionsForProfiling(isolate); | ||
| 219 | - break; | ||
| 220 | - default: | ||
| 221 | - UNREACHABLE(); | ||
| 222 | - break; | ||
| 223 | - } | ||
| 199 | + void SetIsolateErrorHandlers(v8::Isolate* isolate, const IsolateSettings& s) { | ||
| 200 | + if (s.flags & MESSAGE_LISTENER_WITH_ERROR_LEVEL) | ||
| 201 | + isolate->AddMessageListenerWithErrorLevel( | ||
| 202 | + errors::PerIsolateMessageListener, | ||
| 203 | + Isolate::MessageErrorLevel::kMessageError | | ||
| 204 | + Isolate::MessageErrorLevel::kMessageWarning); | ||
| 205 | + | ||
| 206 | + auto* abort_callback = s.should_abort_on_uncaught_exception_callback ? | ||
| 207 | + s.should_abort_on_uncaught_exception_callback : | ||
| 208 | + ShouldAbortOnUncaughtException; | ||
| 209 | + isolate->SetAbortOnUncaughtExceptionCallback(abort_callback); | ||
| 210 | + | ||
| 211 | + auto* fatal_error_cb = s.fatal_error_callback ? | ||
| 212 | + s.fatal_error_callback : OnFatalError; | ||
| 213 | + isolate->SetFatalErrorHandler(fatal_error_cb); | ||
| 214 | + | ||
| 215 | + auto* prepare_stack_trace_cb = s.prepare_stack_trace_callback ? | ||
| 216 | + s.prepare_stack_trace_callback : PrepareStackTraceCallback; | ||
| 217 | + isolate->SetPrepareStackTraceCallback(prepare_stack_trace_cb); | ||
| 218 | + } | ||
| 219 | + | ||
| 220 | + void SetIsolateMiscHandlers(v8::Isolate* isolate, const IsolateSettings& s) { | ||
| 221 | + isolate->SetMicrotasksPolicy(s.policy); | ||
| 222 | + | ||
| 223 | + auto* allow_wasm_codegen_cb = s.allow_wasm_code_generation_callback ? | ||
| 224 | + s.allow_wasm_code_generation_callback : AllowWasmCodeGenerationCallback; | ||
| 225 | + isolate->SetAllowWasmCodeGenerationCallback(allow_wasm_codegen_cb); | ||
| 226 | + | ||
| 227 | + auto* promise_reject_cb = s.promise_reject_callback ? | ||
| 228 | + s.promise_reject_callback : task_queue::PromiseRejectCallback; | ||
| 229 | + isolate->SetPromiseRejectCallback(promise_reject_cb); | ||
| 230 | + | ||
| 231 | + auto* host_cleanup_cb = s.host_cleanup_finalization_group_callback ? | ||
| 232 | + s.host_cleanup_finalization_group_callback : | ||
| 233 | + HostCleanupFinalizationGroupCallback; | ||
| 234 | + isolate->SetHostCleanupFinalizationGroupCallback(host_cleanup_cb); | ||
| 235 | + | ||
| 236 | + if (s.flags & DETAILED_SOURCE_POSITIONS_FOR_PROFILING) | ||
| 237 | + v8::CpuProfiler::UseDetailedSourcePositionsForProfiling(isolate); | ||
| 238 | + } | ||
| 239 | + | ||
| 240 | + void SetIsolateUpForNode(v8::Isolate* isolate, | ||
| 241 | + const IsolateSettings& settings) { | ||
| 242 | + SetIsolateErrorHandlers(isolate, settings); | ||
| 243 | + SetIsolateMiscHandlers(isolate, settings); | ||
| 224 | 244 | } | |
| 225 | 245 | ||
| 226 | 246 | void SetIsolateUpForNode(v8::Isolate* isolate) { | |
| 227 | - SetIsolateUpForNode(isolate, IsolateSettingCategories::kErrorHandlers); | ||
| 228 | - SetIsolateUpForNode(isolate, IsolateSettingCategories::kMisc); | ||
| 247 | + IsolateSettings settings; | ||
| 248 | + SetIsolateUpForNode(isolate, settings); | ||
| 229 | 249 | } | |
| 230 | 250 | ||
| 231 | 251 | Isolate* NewIsolate(ArrayBufferAllocator* allocator, uv_loop_t* event_loop) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -291,9 +291,40 @@ class NODE_EXTERN MultiIsolatePlatform : public v8::Platform { | |||
| 291 | 291 | NODE_EXTERN void SetIsolateCreateParams(v8::Isolate::CreateParams* params, | |
| 292 | 292 | ArrayBufferAllocator* allocator | |
| 293 | 293 | = nullptr); | |
| 294 | + | ||
| 295 | + enum IsolateSettingsFlags { | ||
| 296 | + MESSAGE_LISTENER_WITH_ERROR_LEVEL = 1 << 0, | ||
| 297 | + DETAILED_SOURCE_POSITIONS_FOR_PROFILING = 1 << 1 | ||
| 298 | + }; | ||
| 299 | + | ||
| 300 | + struct IsolateSettings { | ||
| 301 | + uint64_t flags = MESSAGE_LISTENER_WITH_ERROR_LEVEL | | ||
| 302 | + DETAILED_SOURCE_POSITIONS_FOR_PROFILING; | ||
| 303 | + v8::MicrotasksPolicy policy = v8::MicrotasksPolicy::kExplicit; | ||
| 304 | + | ||
| 305 | + // Error handling callbacks | ||
| 306 | + v8::Isolate::AbortOnUncaughtExceptionCallback | ||
| 307 | + should_abort_on_uncaught_exception_callback = nullptr; | ||
| 308 | + v8::FatalErrorCallback fatal_error_callback = nullptr; | ||
| 309 | + v8::PrepareStackTraceCallback prepare_stack_trace_callback = nullptr; | ||
| 310 | + | ||
| 311 | + // Miscellaneous callbacks | ||
| 312 | + v8::PromiseRejectCallback promise_reject_callback = nullptr; | ||
| 313 | + v8::AllowWasmCodeGenerationCallback | ||
| 314 | + allow_wasm_code_generation_callback = nullptr; | ||
| 315 | + v8::HostCleanupFinalizationGroupCallback | ||
| 316 | + host_cleanup_finalization_group_callback = nullptr; | ||
| 317 | + }; | ||
| 318 | + | ||
| 319 | + // Overriding IsolateSettings may produce unexpected behavior | ||
| 320 | + // in Node.js core functionality, so proceed at your own risk. | ||
| 321 | + NODE_EXTERN void SetIsolateUpForNode(v8::Isolate* isolate, | ||
| 322 | + const IsolateSettings& settings); | ||
| 323 | + | ||
| 294 | 324 | // Set a number of callbacks for the `isolate`, in particular the Node.js | |
| 295 | 325 | // uncaught exception listener. | |
| 296 | 326 | NODE_EXTERN void SetIsolateUpForNode(v8::Isolate* isolate); | |
| 327 | + | ||
| 297 | 328 | // Creates a new isolate with Node.js-specific settings. | |
| 298 | 329 | // This is a convenience method equivalent to using SetIsolateCreateParams(), | |
| 299 | 330 | // Isolate::Allocate(), MultiIsolatePlatform::RegisterIsolate(), | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -296,8 +296,8 @@ struct InitializationResult { | |||
| 296 | 296 | }; | |
| 297 | 297 | InitializationResult InitializeOncePerProcess(int argc, char** argv); | |
| 298 | 298 | void TearDownOncePerProcess(); | |
| 299 | - enum class IsolateSettingCategories { kErrorHandlers, kMisc }; | ||
| 300 | - void SetIsolateUpForNode(v8::Isolate* isolate, IsolateSettingCategories cat); | ||
| 299 | + void SetIsolateErrorHandlers(v8::Isolate* isolate, const IsolateSettings& s); | ||
| 300 | + void SetIsolateMiscHandlers(v8::Isolate* isolate, const IsolateSettings& s); | ||
| 301 | 301 | void SetIsolateCreateParamsForNode(v8::Isolate::CreateParams* params); | |
| 302 | 302 | ||
| 303 | 303 | #if HAVE_INSPECTOR | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -30,7 +30,9 @@ NodeMainInstance::NodeMainInstance(Isolate* isolate, | |||
| 30 | 30 | owns_isolate_(false), | |
| 31 | 31 | deserialize_mode_(false) { | |
| 32 | 32 | isolate_data_.reset(new IsolateData(isolate_, event_loop, platform, nullptr)); | |
| 33 | - SetIsolateUpForNode(isolate_, IsolateSettingCategories::kMisc); | ||
| 33 | + | ||
| 34 | + IsolateSettings misc; | ||
| 35 | + SetIsolateMiscHandlers(isolate_, misc); | ||
| 34 | 36 | } | |
| 35 | 37 | ||
| 36 | 38 | std::unique_ptr<NodeMainInstance> NodeMainInstance::Create( | |
@@ -74,11 +76,12 @@ NodeMainInstance::NodeMainInstance( | |||
| 74 | 76 | platform, | |
| 75 | 77 | array_buffer_allocator_.get(), | |
| 76 | 78 | per_isolate_data_indexes)); | |
| 77 | - SetIsolateUpForNode(isolate_, IsolateSettingCategories::kMisc); | ||
| 79 | + IsolateSettings s; | ||
| 80 | + SetIsolateMiscHandlers(isolate_, s); | ||
| 78 | 81 | if (!deserialize_mode_) { | |
| 79 | 82 | // If in deserialize mode, delay until after the deserialization is | |
| 80 | 83 | // complete. | |
| 81 | - SetIsolateUpForNode(isolate_, IsolateSettingCategories::kErrorHandlers); | ||
| 84 | + SetIsolateErrorHandlers(isolate_, s); | ||
| 82 | 85 | } | |
| 83 | 86 | } | |
| 84 | 87 | ||
@@ -182,7 +185,8 @@ std::unique_ptr<Environment> NodeMainInstance::CreateMainEnvironment( | |||
| 182 | 185 | context = | |
| 183 | 186 | Context::FromSnapshot(isolate_, kNodeContextIndex).ToLocalChecked(); | |
| 184 | 187 | InitializeContextRuntime(context); | |
| 185 | - SetIsolateUpForNode(isolate_, IsolateSettingCategories::kErrorHandlers); | ||
| 188 | + IsolateSettings s; | ||
| 189 | + SetIsolateErrorHandlers(isolate_, s); | ||
| 186 | 190 | } else { | |
| 187 | 191 | context = NewContext(isolate_); | |
| 188 | 192 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments