| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -413,6 +413,55 @@ void Initialize(Local<Object> target, | |||
| 413 | 413 | NODE_MODULE_CONTEXT_AWARE_INTERNAL(cares_wrap, Initialize) | |
| 414 | 414 | ``` | |
| 415 | 415 | ||
| 416 | + If the C++ binding is loaded during bootstrap, it needs to be registered | ||
| 417 | + with the utilities in `node_external_reference.h`, like this: | ||
| 418 | + | ||
| 419 | + ```cpp | ||
| 420 | + namespace node { | ||
| 421 | + namespace utils { | ||
| 422 | + void RegisterExternalReferences(ExternalReferenceRegistry* registry) { | ||
| 423 | + registry->Register(GetHiddenValue); | ||
| 424 | + registry->Register(SetHiddenValue); | ||
| 425 | + // ... register all C++ functions used to create FunctionTemplates. | ||
| 426 | + } | ||
| 427 | + } // namespace util | ||
| 428 | + } // namespace node | ||
| 429 | + | ||
| 430 | + // The first argument passed to `NODE_MODULE_EXTERNAL_REFERENCE`, | ||
| 431 | + // which is `util` here, needs to be added to the | ||
| 432 | + // `EXTERNAL_REFERENCE_BINDING_LIST_BASE` list in node_external_reference.h | ||
| 433 | + NODE_MODULE_EXTERNAL_REFERENCE(util, node::util::RegisterExternalReferences) | ||
| 434 | + ``` | ||
| 435 | + | ||
| 436 | + Otherwise, you might see an error message like this when building the | ||
| 437 | + executables: | ||
| 438 | + | ||
| 439 | + ```console | ||
| 440 | + FAILED: gen/node_snapshot.cc | ||
| 441 | + cd ../../; out/Release/node_mksnapshot out/Release/gen/node_snapshot.cc | ||
| 442 | + Unknown external reference 0x107769200. | ||
| 443 | + <unresolved> | ||
| 444 | + /bin/sh: line 1: 6963 Illegal instruction: 4 out/Release/node_mksnapshot out/Release/gen/node_snapshot.cc | ||
| 445 | + ``` | ||
| 446 | + | ||
| 447 | + You can try using a debugger to symbolicate the external reference. For example, | ||
| 448 | + with lldb's `image lookup --address` command (with gdb it's `info symbol`): | ||
| 449 | + | ||
| 450 | + ```console | ||
| 451 | + $ lldb -- out/Release/node_mksnapshot out/Release/gen/node_snapshot.cc | ||
| 452 | + (lldb) run | ||
| 453 | + Process 7012 launched: '/Users/joyee/projects/node/out/Release/node_mksnapshot' (x86_64) | ||
| 454 | + Unknown external reference 0x1004c8200. | ||
| 455 | + <unresolved> | ||
| 456 | + Process 7012 stopped | ||
| 457 | + (lldb) image lookup --address 0x1004c8200 | ||
| 458 | + Address: node_mksnapshot[0x00000001004c8200] (node_mksnapshot.__TEXT.__text + 5009920) | ||
| 459 | + Summary: node_mksnapshot`node::util::GetHiddenValue(v8::FunctionCallbackInfo<v8::Value> const&) at node_util.cc:159 | ||
| 460 | + ``` | ||
| 461 | + | ||
| 462 | + Which explains that the unregistered external reference is | ||
| 463 | + `node::util::GetHiddenValue` defined in `node_util.cc`. | ||
| 464 | + | ||
| 416 | 465 | <a id="per-binding-state"></a> | |
| 417 | 466 | #### Per-binding state | |
| 418 | 467 | ||
@@ -463,6 +512,12 @@ void InitializeHttpParser(Local<Object> target, | |||
| 463 | 512 | } | |
| 464 | 513 | ``` | |
| 465 | 514 | ||
| 515 | + If the binding is loaded during bootstrap, add it to the | ||
| 516 | + `SERIALIZABLE_OBJECT_TYPES` list in `src/node_snapshotable.h` and | ||
| 517 | + inherit from the `SnapshotableObject` class instead. See the comments | ||
| 518 | + of `SnapshotableObject` on how to implement its serialization and | ||
| 519 | + deserialization. | ||
| 520 | + | ||
| 466 | 521 | <a id="exception-handling"></a> | |
| 467 | 522 | ### Exception handling | |
| 468 | 523 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments