|
23 | 23 | #include "aliased_buffer.h"
|
24 | 24 | #include "memory_tracker-inl.h"
|
25 | 25 | #include "node_buffer.h"
|
| 26 | +#include "node_external_reference.h" |
26 | 27 | #include "node_process.h"
|
27 | 28 | #include "node_stat_watcher.h"
|
28 | 29 | #include "util-inl.h"
|
@@ -2398,6 +2399,47 @@ void BindingData::MemoryInfo(MemoryTracker* tracker) const {
|
2398 | 2399 | file_handle_read_wrap_freelist);
|
2399 | 2400 | }
|
2400 | 2401 |
|
| 2402 | +BindingData::BindingData(Environment* env, v8::Local<v8::Object> wrap) |
| 2403 | + : SnapshotableObject(env, wrap, type_int), |
| 2404 | + stats_field_array(env->isolate(), kFsStatsBufferLength), |
| 2405 | + stats_field_bigint_array(env->isolate(), kFsStatsBufferLength) { |
| 2406 | + wrap->Set(env->context(), |
| 2407 | + FIXED_ONE_BYTE_STRING(env->isolate(), "statValues"), |
| 2408 | + stats_field_array.GetJSArray()) |
| 2409 | + .Check(); |
| 2410 | + |
| 2411 | + wrap->Set(env->context(), |
| 2412 | + FIXED_ONE_BYTE_STRING(env->isolate(), "bigintStatValues"), |
| 2413 | + stats_field_bigint_array.GetJSArray()) |
| 2414 | + .Check(); |
| 2415 | +} |
| 2416 | + |
| 2417 | +void BindingData::Deserialize(Local<Context> context, |
| 2418 | + Local<Object> holder, |
| 2419 | + int index, |
| 2420 | + InternalFieldInfo* info) { |
| 2421 | + DCHECK_EQ(index, BaseObject::kSlot); |
| 2422 | + HandleScope scope(context->GetIsolate()); |
| 2423 | + Environment* env = Environment::GetCurrent(context); |
| 2424 | + BindingData* binding = env->AddBindingData<BindingData>(context, holder); |
| 2425 | + CHECK_NOT_NULL(binding); |
| 2426 | +} |
| 2427 | + |
| 2428 | +void BindingData::PrepareForSerialization(Local<Context> context, |
| 2429 | + v8::SnapshotCreator* creator) { |
| 2430 | + CHECK(file_handle_read_wrap_freelist.empty()); |
| 2431 | + // We'll just re-initialize the buffers in the constructor since their |
| 2432 | + // contents can be thrown away once consumed in the previous call. |
| 2433 | + stats_field_array.Release(); |
| 2434 | + stats_field_bigint_array.Release(); |
| 2435 | +} |
| 2436 | + |
| 2437 | +InternalFieldInfo* BindingData::Serialize(int index) { |
| 2438 | + DCHECK_EQ(index, BaseObject::kSlot); |
| 2439 | + InternalFieldInfo* info = InternalFieldInfo::New(type()); |
| 2440 | + return info; |
| 2441 | +} |
| 2442 | + |
2401 | 2443 | // TODO(addaleax): Remove once we're on C++17.
|
2402 | 2444 | constexpr FastStringKey BindingData::type_name;
|
2403 | 2445 |
|
@@ -2461,14 +2503,6 @@ void Initialize(Local<Object> target,
|
2461 | 2503 | static_cast<int32_t>(FsStatsOffset::kFsStatsFieldsNumber)))
|
2462 | 2504 | .Check();
|
2463 | 2505 |
|
2464 |
| - target->Set(context, |
2465 |
| - FIXED_ONE_BYTE_STRING(isolate, "statValues"), |
2466 |
| - binding_data->stats_field_array.GetJSArray()).Check(); |
2467 |
| - |
2468 |
| - target->Set(context, |
2469 |
| - FIXED_ONE_BYTE_STRING(isolate, "bigintStatValues"), |
2470 |
| - binding_data->stats_field_bigint_array.GetJSArray()).Check(); |
2471 |
| - |
2472 | 2506 | StatWatcher::Initialize(env, target);
|
2473 | 2507 |
|
2474 | 2508 | // Create FunctionTemplate for FSReqCallback
|
@@ -2532,8 +2566,62 @@ void Initialize(Local<Object> target,
|
2532 | 2566 | BindingData* FSReqBase::binding_data() {
|
2533 | 2567 | return binding_data_.get();
|
2534 | 2568 | }
|
| 2569 | + |
| 2570 | +void RegisterExternalReferences(ExternalReferenceRegistry* registry) { |
| 2571 | + registry->Register(Access); |
| 2572 | + StatWatcher::RegisterExternalReferences(registry); |
| 2573 | + |
| 2574 | + registry->Register(Close); |
| 2575 | + registry->Register(Open); |
| 2576 | + registry->Register(OpenFileHandle); |
| 2577 | + registry->Register(Read); |
| 2578 | + registry->Register(ReadBuffers); |
| 2579 | + registry->Register(Fdatasync); |
| 2580 | + registry->Register(Fsync); |
| 2581 | + registry->Register(Rename); |
| 2582 | + registry->Register(FTruncate); |
| 2583 | + registry->Register(RMDir); |
| 2584 | + registry->Register(MKDir); |
| 2585 | + registry->Register(ReadDir); |
| 2586 | + registry->Register(InternalModuleReadJSON); |
| 2587 | + registry->Register(InternalModuleStat); |
| 2588 | + registry->Register(Stat); |
| 2589 | + registry->Register(LStat); |
| 2590 | + registry->Register(FStat); |
| 2591 | + registry->Register(Link); |
| 2592 | + registry->Register(Symlink); |
| 2593 | + registry->Register(ReadLink); |
| 2594 | + registry->Register(Unlink); |
| 2595 | + registry->Register(WriteBuffer); |
| 2596 | + registry->Register(WriteBuffers); |
| 2597 | + registry->Register(WriteString); |
| 2598 | + registry->Register(RealPath); |
| 2599 | + registry->Register(CopyFile); |
| 2600 | + |
| 2601 | + registry->Register(Chmod); |
| 2602 | + registry->Register(FChmod); |
| 2603 | + // registry->Register(LChmod); |
| 2604 | + |
| 2605 | + registry->Register(Chown); |
| 2606 | + registry->Register(FChown); |
| 2607 | + registry->Register(LChown); |
| 2608 | + |
| 2609 | + registry->Register(UTimes); |
| 2610 | + registry->Register(FUTimes); |
| 2611 | + registry->Register(LUTimes); |
| 2612 | + |
| 2613 | + registry->Register(Mkdtemp); |
| 2614 | + registry->Register(NewFSReqCallback); |
| 2615 | + |
| 2616 | + registry->Register(FileHandle::New); |
| 2617 | + registry->Register(FileHandle::Close); |
| 2618 | + registry->Register(FileHandle::ReleaseFD); |
| 2619 | + StreamBase::RegisterExternalReferences(registry); |
| 2620 | +} |
| 2621 | + |
2535 | 2622 | } // namespace fs
|
2536 | 2623 |
|
2537 | 2624 | } // end namespace node
|
2538 | 2625 |
|
2539 | 2626 | NODE_MODULE_CONTEXT_AWARE_INTERNAL(fs, node::fs::Initialize)
|
| 2627 | +NODE_MODULE_EXTERNAL_REFERENCE(fs, node::fs::RegisterExternalReferences) |
0 commit comments