| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent c0b6413 commit 25069a6
12 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -81,14 +81,11 @@ const { | |||
| 81 | 81 | Symbol, | |
| 82 | 82 | } = primordials; | |
| 83 | 83 | ||
| 84 | + const binding = internalBinding('timers'); | ||
| 84 | 85 | const { | |
| 85 | - scheduleTimer, | ||
| 86 | - toggleTimerRef, | ||
| 87 | - getLibuvNow, | ||
| 88 | 86 | immediateInfo, | |
| 89 | 87 | timeoutInfo, | |
| 90 | - toggleImmediateRef, | ||
| 91 | - } = internalBinding('timers'); | ||
| 88 | + } = binding; | ||
| 92 | 89 | ||
| 93 | 90 | const { | |
| 94 | 91 | getDefaultTriggerAsyncId, | |
@@ -306,13 +303,17 @@ class ImmediateList { | |||
| 306 | 303 | const immediateQueue = new ImmediateList(); | |
| 307 | 304 | ||
| 308 | 305 | function incRefCount() { | |
| 309 | - if (timeoutInfo[0]++ === 0) | ||
| 310 | - toggleTimerRef(true); | ||
| 306 | + if (timeoutInfo[0]++ === 0) { | ||
| 307 | + // We need to use the binding as the receiver for fast API calls. | ||
| 308 | + binding.toggleTimerRef(true); | ||
| 309 | + } | ||
| 311 | 310 | } | |
| 312 | 311 | ||
| 313 | 312 | function decRefCount() { | |
| 314 | - if (--timeoutInfo[0] === 0) | ||
| 315 | - toggleTimerRef(false); | ||
| 313 | + if (--timeoutInfo[0] === 0) { | ||
| 314 | + // We need to use the binding as the receiver for fast API calls. | ||
| 315 | + binding.toggleTimerRef(false); | ||
| 316 | + } | ||
| 316 | 317 | } | |
| 317 | 318 | ||
| 318 | 319 | // Schedule or re-schedule a timer. | |
@@ -356,7 +357,8 @@ function insertGuarded(item, refed, start) { | |||
| 356 | 357 | item[kRefed] = refed; | |
| 357 | 358 | } | |
| 358 | 359 | ||
| 359 | - function insert(item, msecs, start = getLibuvNow()) { | ||
| 360 | + // We need to use the binding as the receiver for fast API calls. | ||
| 361 | + function insert(item, msecs, start = binding.getLibuvNow()) { | ||
| 360 | 362 | // Truncate so that accuracy of sub-millisecond timers is not assumed. | |
| 361 | 363 | msecs = MathTrunc(msecs); | |
| 362 | 364 | item._idleStart = start; | |
@@ -370,7 +372,8 @@ function insert(item, msecs, start = getLibuvNow()) { | |||
| 370 | 372 | timerListQueue.insert(list); | |
| 371 | 373 | ||
| 372 | 374 | if (nextExpiry > expiry) { | |
| 373 | - scheduleTimer(msecs); | ||
| 375 | + // We need to use the binding as the receiver for fast API calls. | ||
| 376 | + binding.scheduleTimer(msecs); | ||
| 374 | 377 | nextExpiry = expiry; | |
| 375 | 378 | } | |
| 376 | 379 | } | |
@@ -559,8 +562,10 @@ function getTimerCallbacks(runNextTicks) { | |||
| 559 | 562 | emitBefore(asyncId, timer[trigger_async_id_symbol], timer); | |
| 560 | 563 | ||
| 561 | 564 | let start; | |
| 562 | - if (timer._repeat) | ||
| 563 | - start = getLibuvNow(); | ||
| 565 | + if (timer._repeat) { | ||
| 566 | + // We need to use the binding as the receiver for fast API calls. | ||
| 567 | + start = binding.getLibuvNow(); | ||
| 568 | + } | ||
| 564 | 569 | ||
| 565 | 570 | try { | |
| 566 | 571 | const args = timer._timerArgs; | |
@@ -627,17 +632,22 @@ class Immediate { | |||
| 627 | 632 | ref() { | |
| 628 | 633 | if (this[kRefed] === false) { | |
| 629 | 634 | this[kRefed] = true; | |
| 630 | - if (immediateInfo[kRefCount]++ === 0) | ||
| 631 | - toggleImmediateRef(true); | ||
| 635 | + | ||
| 636 | + if (immediateInfo[kRefCount]++ === 0) { | ||
| 637 | + // We need to use the binding as the receiver for fast API calls. | ||
| 638 | + binding.toggleImmediateRef(true); | ||
| 639 | + } | ||
| 632 | 640 | } | |
| 633 | 641 | return this; | |
| 634 | 642 | } | |
| 635 | 643 | ||
| 636 | 644 | unref() { | |
| 637 | 645 | if (this[kRefed] === true) { | |
| 638 | 646 | this[kRefed] = false; | |
| 639 | - if (--immediateInfo[kRefCount] === 0) | ||
| 640 | - toggleImmediateRef(false); | ||
| 647 | + if (--immediateInfo[kRefCount] === 0) { | ||
| 648 | + // We need to use the binding as the receiver for fast API calls. | ||
| 649 | + binding.toggleImmediateRef(false); | ||
| 650 | + } | ||
| 641 | 651 | } | |
| 642 | 652 | return this; | |
| 643 | 653 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -27,10 +27,10 @@ const { | |||
| 27 | 27 | SymbolToPrimitive | |
| 28 | 28 | } = primordials; | |
| 29 | 29 | ||
| 30 | + const binding = internalBinding('timers'); | ||
| 30 | 31 | const { | |
| 31 | 32 | immediateInfo, | |
| 32 | - toggleImmediateRef | ||
| 33 | - } = internalBinding('timers'); | ||
| 33 | + } = binding; | ||
| 34 | 34 | const L = require('internal/linkedlist'); | |
| 35 | 35 | const { | |
| 36 | 36 | async_id_symbol, | |
@@ -323,8 +323,10 @@ function clearImmediate(immediate) { | |||
| 323 | 323 | immediateInfo[kCount]--; | |
| 324 | 324 | immediate._destroyed = true; | |
| 325 | 325 | ||
| 326 | - if (immediate[kRefed] && --immediateInfo[kRefCount] === 0) | ||
| 327 | - toggleImmediateRef(false); | ||
| 326 | + if (immediate[kRefed] && --immediateInfo[kRefCount] === 0) { | ||
| 327 | + // We need to use the binding as the receiver for fast API calls. | ||
| 328 | + binding.toggleImmediateRef(false); | ||
| 329 | + } | ||
| 328 | 330 | immediate[kRefed] = null; | |
| 329 | 331 | ||
| 330 | 332 | if (destroyHooksExist() && immediate[async_id_symbol] !== undefined) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -668,6 +668,7 @@ | |||
| 668 | 668 | 'src/string_decoder-inl.h', | |
| 669 | 669 | 'src/string_search.h', | |
| 670 | 670 | 'src/tcp_wrap.h', | |
| 671 | + 'src/timers.h', | ||
| 671 | 672 | 'src/tracing/agent.h', | |
| 672 | 673 | 'src/tracing/node_trace_buffer.h', | |
| 673 | 674 | 'src/tracing/node_trace_writer.h', | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -13,7 +13,8 @@ namespace node { | |||
| 13 | 13 | V(fs_binding_data, fs::BindingData) \ | |
| 14 | 14 | V(v8_binding_data, v8_utils::BindingData) \ | |
| 15 | 15 | V(blob_binding_data, BlobBindingData) \ | |
| 16 | - V(process_binding_data, process::BindingData) | ||
| 16 | + V(process_binding_data, process::BindingData) \ | ||
| 17 | + V(timers_binding_data, timers::BindingData) | ||
| 17 | 18 | ||
| 18 | 19 | #define UNSERIALIZABLE_BINDING_TYPES(V) \ | |
| 19 | 20 | V(http2_binding_data, http2::BindingData) \ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1273,12 +1273,16 @@ void Environment::ToggleImmediateRef(bool ref) { | |||
| 1273 | 1273 | } | |
| 1274 | 1274 | } | |
| 1275 | 1275 | ||
| 1276 | - | ||
| 1277 | - Local<Value> Environment::GetNow() { | ||
| 1276 | + uint64_t Environment::GetNowUint64() { | ||
| 1278 | 1277 | uv_update_time(event_loop()); | |
| 1279 | 1278 | uint64_t now = uv_now(event_loop()); | |
| 1280 | 1279 | CHECK_GE(now, timer_base()); | |
| 1281 | 1280 | now -= timer_base(); | |
| 1281 | + return now; | ||
| 1282 | + } | ||
| 1283 | + | ||
| 1284 | + Local<Value> Environment::GetNow() { | ||
| 1285 | + uint64_t now = GetNowUint64(); | ||
| 1282 | 1286 | if (now <= 0xffffffff) | |
| 1283 | 1287 | return Integer::NewFromUnsigned(isolate(), static_cast<uint32_t>(now)); | |
| 1284 | 1288 | else | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -887,6 +887,8 @@ class Environment : public MemoryRetainer { | |||
| 887 | 887 | static inline Environment* ForAsyncHooks(AsyncHooks* hooks); | |
| 888 | 888 | ||
| 889 | 889 | v8::Local<v8::Value> GetNow(); | |
| 890 | + uint64_t GetNowUint64(); | ||
| 891 | + | ||
| 890 | 892 | void ScheduleTimer(int64_t duration); | |
| 891 | 893 | void ToggleTimerRef(bool ref); | |
| 892 | 894 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -13,6 +13,12 @@ namespace node { | |||
| 13 | 13 | using CFunctionCallbackWithOneByteString = | |
| 14 | 14 | uint32_t (*)(v8::Local<v8::Value>, const v8::FastOneByteString&); | |
| 15 | 15 | using CFunctionCallback = void (*)(v8::Local<v8::Value> receiver); | |
| 16 | + using CFunctionCallbackReturnDouble = | ||
| 17 | + double (*)(v8::Local<v8::Object> receiver); | ||
| 18 | + using CFunctionCallbackWithInt64 = void (*)(v8::Local<v8::Object> receiver, | ||
| 19 | + int64_t); | ||
| 20 | + using CFunctionCallbackWithBool = void (*)(v8::Local<v8::Object> receiver, | ||
| 21 | + bool); | ||
| 16 | 22 | ||
| 17 | 23 | // This class manages the external references from the V8 heap | |
| 18 | 24 | // to the C++ addresses in Node.js. | |
@@ -23,6 +29,9 @@ class ExternalReferenceRegistry { | |||
| 23 | 29 | #define ALLOWED_EXTERNAL_REFERENCE_TYPES(V) \ | |
| 24 | 30 | V(CFunctionCallback) \ | |
| 25 | 31 | V(CFunctionCallbackWithOneByteString) \ | |
| 32 | + V(CFunctionCallbackReturnDouble) \ | ||
| 33 | + V(CFunctionCallbackWithInt64) \ | ||
| 34 | + V(CFunctionCallbackWithBool) \ | ||
| 26 | 35 | V(const v8::CFunctionInfo*) \ | |
| 27 | 36 | V(v8::FunctionCallback) \ | |
| 28 | 37 | V(v8::AccessorGetterCallback) \ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -20,6 +20,7 @@ | |||
| 20 | 20 | #include "node_util.h" | |
| 21 | 21 | #include "node_v8.h" | |
| 22 | 22 | #include "node_v8_platform-inl.h" | |
| 23 | + #include "timers.h" | ||
| 23 | 24 | ||
| 24 | 25 | #if HAVE_INSPECTOR | |
| 25 | 26 | #include "inspector/worker_inspector.h" // ParentInspectorHandle | |
| Back | FazBrowse Home | New Git URL |
0 commit comments