| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent c2757d1 commit bf4c39d
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 | |
|---|---|---|---|
@@ -280,9 +280,39 @@ class NODE_EXTERN MultiIsolatePlatform : public v8::Platform { | |||
| 280 | 280 | void* data) = 0; | |
| 281 | 281 | }; | |
| 282 | 282 | ||
| 283 | + enum IsolateSettingsFlags { | ||
| 284 | + MESSAGE_LISTENER_WITH_ERROR_LEVEL = 1 << 0, | ||
| 285 | + DETAILED_SOURCE_POSITIONS_FOR_PROFILING = 1 << 1 | ||
| 286 | + }; | ||
| 287 | + | ||
| 288 | + struct IsolateSettings { | ||
| 289 | + uint64_t flags = MESSAGE_LISTENER_WITH_ERROR_LEVEL | | ||
| 290 | + DETAILED_SOURCE_POSITIONS_FOR_PROFILING; | ||
| 291 | + v8::MicrotasksPolicy policy = v8::MicrotasksPolicy::kExplicit; | ||
| 292 | + | ||
| 293 | + // Error handling callbacks | ||
| 294 | + v8::Isolate::AbortOnUncaughtExceptionCallback | ||
| 295 | + should_abort_on_uncaught_exception_callback = nullptr; | ||
| 296 | + v8::FatalErrorCallback fatal_error_callback = nullptr; | ||
| 297 | + v8::PrepareStackTraceCallback prepare_stack_trace_callback = nullptr; | ||
| 298 | + | ||
| 299 | + // Miscellaneous callbacks | ||
| 300 | + v8::PromiseRejectCallback promise_reject_callback = nullptr; | ||
| 301 | + v8::AllowWasmCodeGenerationCallback | ||
| 302 | + allow_wasm_code_generation_callback = nullptr; | ||
| 303 | + v8::HostCleanupFinalizationGroupCallback | ||
| 304 | + host_cleanup_finalization_group_callback = nullptr; | ||
| 305 | + }; | ||
| 306 | + | ||
| 307 | + // Overriding IsolateSettings may produce unexpected behavior | ||
| 308 | + // in Node.js core functionality, so proceed at your own risk. | ||
| 309 | + NODE_EXTERN void SetIsolateUpForNode(v8::Isolate* isolate, | ||
| 310 | + const IsolateSettings& settings); | ||
| 311 | + | ||
| 283 | 312 | // Set a number of callbacks for the `isolate`, in particular the Node.js | |
| 284 | 313 | // uncaught exception listener. | |
| 285 | 314 | NODE_EXTERN void SetIsolateUpForNode(v8::Isolate* isolate); | |
| 315 | + | ||
| 286 | 316 | // Creates a new isolate with Node.js-specific settings. | |
| 287 | 317 | // This is a convenience method equivalent to using SetIsolateCreateParams(), | |
| 288 | 318 | // Isolate::Allocate(), MultiIsolatePlatform::RegisterIsolate(), | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -313,8 +313,8 @@ struct InitializationResult { | |||
| 313 | 313 | }; | |
| 314 | 314 | InitializationResult InitializeOncePerProcess(int argc, char** argv); | |
| 315 | 315 | void TearDownOncePerProcess(); | |
| 316 | - enum class IsolateSettingCategories { kErrorHandlers, kMisc }; | ||
| 317 | - void SetIsolateUpForNode(v8::Isolate* isolate, IsolateSettingCategories cat); | ||
| 316 | + void SetIsolateErrorHandlers(v8::Isolate* isolate, const IsolateSettings& s); | ||
| 317 | + void SetIsolateMiscHandlers(v8::Isolate* isolate, const IsolateSettings& s); | ||
| 318 | 318 | void SetIsolateCreateParamsForNode(v8::Isolate::CreateParams* params); | |
| 319 | 319 | ||
| 320 | 320 | #if HAVE_INSPECTOR | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -35,7 +35,9 @@ NodeMainInstance::NodeMainInstance(Isolate* isolate, | |||
| 35 | 35 | owns_isolate_(false), | |
| 36 | 36 | deserialize_mode_(false) { | |
| 37 | 37 | isolate_data_.reset(new IsolateData(isolate_, event_loop, platform, nullptr)); | |
| 38 | - SetIsolateUpForNode(isolate_, IsolateSettingCategories::kMisc); | ||
| 38 | + | ||
| 39 | + IsolateSettings misc; | ||
| 40 | + SetIsolateMiscHandlers(isolate_, misc); | ||
| 39 | 41 | } | |
| 40 | 42 | ||
| 41 | 43 | std::unique_ptr<NodeMainInstance> NodeMainInstance::Create( | |
@@ -79,11 +81,12 @@ NodeMainInstance::NodeMainInstance( | |||
| 79 | 81 | platform, | |
| 80 | 82 | array_buffer_allocator_.get(), | |
| 81 | 83 | per_isolate_data_indexes)); | |
| 82 | - SetIsolateUpForNode(isolate_, IsolateSettingCategories::kMisc); | ||
| 84 | + IsolateSettings s; | ||
| 85 | + SetIsolateMiscHandlers(isolate_, s); | ||
| 83 | 86 | if (!deserialize_mode_) { | |
| 84 | 87 | // If in deserialize mode, delay until after the deserialization is | |
| 85 | 88 | // complete. | |
| 86 | - SetIsolateUpForNode(isolate_, IsolateSettingCategories::kErrorHandlers); | ||
| 89 | + SetIsolateErrorHandlers(isolate_, s); | ||
| 87 | 90 | } | |
| 88 | 91 | } | |
| 89 | 92 | ||
@@ -201,7 +204,8 @@ std::unique_ptr<Environment> NodeMainInstance::CreateMainEnvironment( | |||
| 201 | 204 | context = | |
| 202 | 205 | Context::FromSnapshot(isolate_, kNodeContextIndex).ToLocalChecked(); | |
| 203 | 206 | InitializeContextRuntime(context); | |
| 204 | - SetIsolateUpForNode(isolate_, IsolateSettingCategories::kErrorHandlers); | ||
| 207 | + IsolateSettings s; | ||
| 208 | + SetIsolateErrorHandlers(isolate_, s); | ||
| 205 | 209 | } else { | |
| 206 | 210 | context = NewContext(isolate_); | |
| 207 | 211 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments