Skip to content

Commit 3e52041

Browse files
committed
Fix for TTD with fs stat changes.
Signed-off-by: Mark Marron <[email protected]>
1 parent b7a68b5 commit 3e52041

File tree

6 files changed

+35
-20
lines changed

6 files changed

+35
-20
lines changed

deps/chakrashim/include/v8.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,7 @@ class PersistentBase {
533533

534534
private:
535535
template<class F> friend class Local;
536+
template<class F> friend class Global;
536537
template<class F1, class F2> friend class Persistent;
537538

538539
explicit V8_INLINE PersistentBase(T* val)

src/env-inl.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ inline Environment::Environment(IsolateData* isolate_data,
199199
#endif
200200
handle_cleanup_waiting_(0),
201201
http_parser_buffer_(nullptr),
202-
fs_stats_field_array_(nullptr),
202+
fs_stats_field_array_(),
203203
context_(context->GetIsolate(), context) {
204204
// We'll be creating new objects so make sure we've entered the context.
205205
v8::HandleScope handle_scope(isolate());
@@ -245,6 +245,8 @@ inline Environment::~Environment() {
245245
while (handle_cleanup_waiting_ != 0)
246246
uv_run(event_loop(), UV_RUN_ONCE);
247247

248+
fs_stats_field_array_.Empty();
249+
248250
context()->SetAlignedPointerInEmbedderData(kContextEmbedderDataIndex,
249251
nullptr);
250252
#define V(PropertyName, TypeName) PropertyName ## _.Reset();
@@ -381,13 +383,13 @@ inline void Environment::set_http_parser_buffer(char* buffer) {
381383
http_parser_buffer_ = buffer;
382384
}
383385

384-
inline double* Environment::fs_stats_field_array() const {
385-
return fs_stats_field_array_;
386+
inline v8::Local<v8::Float64Array> Environment::fs_stats_field_array() const {
387+
return v8::Local<v8::Float64Array>::New(isolate_, fs_stats_field_array_);
386388
}
387389

388-
inline void Environment::set_fs_stats_field_array(double* fields) {
389-
CHECK_EQ(fs_stats_field_array_, nullptr); // Should be set only once.
390-
fs_stats_field_array_ = fields;
390+
inline void Environment::set_fs_stats_field_array(v8::Local<v8::Float64Array> fields) {
391+
CHECK_EQ(fs_stats_field_array_.IsEmpty(), true); // Should be set only once.
392+
fs_stats_field_array_ = v8::Global<v8::Float64Array>::Global(isolate_, fields);
391393
}
392394

393395
inline Environment* Environment::from_cares_timer_handle(uv_timer_t* handle) {

src/env.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -491,8 +491,8 @@ class Environment {
491491
inline char* http_parser_buffer() const;
492492
inline void set_http_parser_buffer(char* buffer);
493493

494-
inline double* fs_stats_field_array() const;
495-
inline void set_fs_stats_field_array(double* fields);
494+
inline v8::Local<v8::Float64Array> fs_stats_field_array() const;
495+
inline void set_fs_stats_field_array(v8::Local<v8::Float64Array> fields);
496496

497497
inline void ThrowError(const char* errmsg);
498498
inline void ThrowTypeError(const char* errmsg);
@@ -602,7 +602,8 @@ class Environment {
602602

603603
char* http_parser_buffer_;
604604

605-
double* fs_stats_field_array_;
605+
//We depend on the property in fs.js to manage the lifetime appropriately
606+
v8::Global<v8::Float64Array> fs_stats_field_array_;
606607

607608
#define V(PropertyName, TypeName) \
608609
v8::Persistent<TypeName> PropertyName ## _;

src/node_file.cc

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,10 @@ static void Close(const FunctionCallbackInfo<Value>& args) {
448448
}
449449

450450

451-
void FillStatsArray(double* fields, const uv_stat_t* s) {
451+
void FillStatsArray(v8::Local<v8::Float64Array> fields_array, const uv_stat_t* s, int offset) {
452+
Local<ArrayBuffer> ab = fields_array->Buffer();
453+
double* fields = static_cast<double*>(ab->GetContents().Data()) + offset;
454+
452455
fields[0] = s->st_dev;
453456
fields[1] = s->st_mode;
454457
fields[2] = s->st_nlink;
@@ -477,6 +480,12 @@ void FillStatsArray(double* fields, const uv_stat_t* s) {
477480
X(12, ctim)
478481
X(13, birthtim)
479482
#undef X
483+
484+
#if ENABLE_TTD_NODE
485+
if(s_doTTRecord || s_doTTReplay) {
486+
ab->TTDRawBufferModifyNotifySync(offset * sizeof(double), 14 * sizeof(double));
487+
}
488+
#endif
480489
}
481490

482491
// Used to speed up module loading. Returns the contents of the file as
@@ -1392,18 +1401,20 @@ static void Mkdtemp(const FunctionCallbackInfo<Value>& args) {
13921401

13931402
void GetStatValues(const FunctionCallbackInfo<Value>& args) {
13941403
Environment* env = Environment::GetCurrent(args);
1395-
double* fields = env->fs_stats_field_array();
1396-
if (fields == nullptr) {
1404+
Local<Float64Array> fields = env->fs_stats_field_array();
1405+
1406+
if (fields.IsEmpty()) {
13971407
// stat fields contains twice the number of entries because `fs.StatWatcher`
13981408
// needs room to store data for *two* `fs.Stats` instances.
1399-
fields = new double[2 * 14];
1409+
Local<ArrayBuffer> ab = ArrayBuffer::New(env->isolate(),
1410+
new double[2 * 14],
1411+
sizeof(double) * 2 * 14);
1412+
fields = Float64Array::New(ab, 0, 2 * 14);
1413+
14001414
env->set_fs_stats_field_array(fields);
14011415
}
1402-
Local<ArrayBuffer> ab = ArrayBuffer::New(env->isolate(),
1403-
fields,
1404-
sizeof(double) * 2 * 14);
1405-
Local<Float64Array> fields_array = Float64Array::New(ab, 0, 2 * 14);
1406-
args.GetReturnValue().Set(fields_array);
1416+
1417+
args.GetReturnValue().Set(fields);
14071418
}
14081419

14091420
void InitFs(Local<Object> target,

src/node_internals.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ NO_RETURN void FatalError(const char* location, const char* message);
162162

163163
void ProcessEmitWarning(Environment* env, const char* fmt, ...);
164164

165-
void FillStatsArray(double* fields, const uv_stat_t* s);
165+
void FillStatsArray(v8::Local<v8::Float64Array> fields_array, const uv_stat_t* s, int offset = 0);
166166

167167
void SetupProcessObject(Environment* env,
168168
int argc,

src/node_stat_watcher.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ void StatWatcher::Callback(uv_fs_poll_t* handle,
8888
Context::Scope context_scope(env->context());
8989

9090
FillStatsArray(env->fs_stats_field_array(), curr);
91-
FillStatsArray(env->fs_stats_field_array() + 14, prev);
91+
FillStatsArray(env->fs_stats_field_array(), prev, 14);
9292
Local<Value> arg = Integer::New(env->isolate(), status);
9393
wrap->MakeCallback(env->onchange_string(), 1, &arg);
9494
}

0 commit comments

Comments
 (0)