return fields_[kCount];
}
-inline Environment::TickInfo::TickInfo() {
+inline Environment::TickInfo::TickInfo() : in_tick_(false), last_threw_(false) {
for (int i = 0; i < kFieldsCount; ++i) fields_[i] = 0;
}
return kFieldsCount;
}
-inline uint32_t Environment::TickInfo::in_tick() const {
- return fields_[kInTick];
+inline bool Environment::TickInfo::in_tick() const {
+ return in_tick_;
}
inline uint32_t Environment::TickInfo::index() const {
return fields_[kIndex];
}
-inline uint32_t Environment::TickInfo::last_threw() const {
- return fields_[kLastThrew];
+inline bool Environment::TickInfo::last_threw() const {
+ return last_threw_;
}
inline uint32_t Environment::TickInfo::length() const {
return fields_[kLength];
}
+inline void Environment::TickInfo::set_in_tick(bool value) {
+ in_tick_ = value;
+}
+
inline void Environment::TickInfo::set_index(uint32_t value) {
fields_[kIndex] = value;
}
-inline void Environment::TickInfo::set_last_threw(uint32_t value) {
- fields_[kLastThrew] = value;
+inline void Environment::TickInfo::set_last_threw(bool value) {
+ last_threw_ = value;
}
inline Environment* Environment::New(v8::Local<v8::Context> context) {
public:
inline uint32_t* fields();
inline int fields_count() const;
- inline uint32_t in_tick() const;
+ inline bool in_tick() const;
+ inline bool last_threw() const;
inline uint32_t index() const;
- inline uint32_t last_threw() const;
inline uint32_t length() const;
+ inline void set_in_tick(bool value);
inline void set_index(uint32_t value);
- inline void set_last_threw(uint32_t value);
+ inline void set_last_threw(bool value);
private:
friend class Environment; // So we can call the constructor.
inline TickInfo();
enum Fields {
- kInTick,
kIndex,
- kLastThrew,
kLength,
kFieldsCount
};
uint32_t fields_[kFieldsCount];
+ bool in_tick_;
+ bool last_threw_;
DISALLOW_COPY_AND_ASSIGN(TickInfo);
};
return ret;
}
- if (tick_info->in_tick() == 1) {
+ if (tick_info->in_tick()) {
return ret;
}
return ret;
}
+ tick_info->set_in_tick(true);
+
// process nextTicks after call
Local<Object> process_object = env->process_object();
Local<Function> tick_callback_function = env->tick_callback_function();
tick_callback_function->Call(process_object, 0, NULL);
+ tick_info->set_in_tick(false);
+
if (try_catch.HasCaught()) {
+ tick_info->set_last_threw(true);
return Undefined(node_isolate);
}
return ret;
}
+ tick_info->set_in_tick(true);
+
// lazy load no domain next tick callbacks
Local<Function> tick_callback_function = env->tick_callback_function();
if (tick_callback_function.IsEmpty()) {
// process nextTicks after call
tick_callback_function->Call(process_object, 0, NULL);
+ tick_info->set_in_tick(false);
+
if (try_catch.HasCaught()) {
+ tick_info->set_last_threw(true);
return Undefined(node_isolate);
}
var tickInfo = process._tickInfo;
// *Must* match Environment::TickInfo::Fields in src/env.h.
- var kInTick = 0;
- var kIndex = 1;
- var kLastThrew = 2;
- var kLength = 3;
+ var kIndex = 0;
+ var kLength = 1;
process.nextTick = nextTick;
// needs to be accessible from cc land
tickInfo[kLength] = nextTickQueue.length;
}
}
- tickInfo[kInTick] = 0;
tickInfo[kIndex] = 0;
}
function _tickCallback() {
var callback, threw;
- tickInfo[kInTick] = 1;
-
while (tickInfo[kIndex] < tickInfo[kLength]) {
callback = nextTickQueue[tickInfo[kIndex]++].callback;
threw = true;
}
function _tickDomainCallback() {
- var tock, callback, domain;
-
- tickInfo[kInTick] = 1;
+ var tock, callback, threw, domain;
while (tickInfo[kIndex] < tickInfo[kLength]) {
tock = nextTickQueue[tickInfo[kIndex]++];
if (domain._disposed) continue;
domain.enter();
}
- tickInfo[kLastThrew] = 1;
+ threw = true;
try {
callback();
- tickInfo[kLastThrew] = 0;
+ threw = false;
} finally {
- if (tickInfo[kLastThrew] === 1) tickDone();
+ if (threw) tickDone();
}
if (domain)
domain.exit();