| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -26,7 +26,8 @@ const { | |||
| 26 | 26 | getHiddenValue, | |
| 27 | 27 | setHiddenValue, | |
| 28 | 28 | arrow_message_private_symbol: kArrowMessagePrivateSymbolIndex, | |
| 29 | - decorated_private_symbol: kDecoratedPrivateSymbolIndex | ||
| 29 | + decorated_private_symbol: kDecoratedPrivateSymbolIndex, | ||
| 30 | + sleep: _sleep | ||
| 30 | 31 | } = internalBinding('util'); | |
| 31 | 32 | const { isNativeError } = internalBinding('types'); | |
| 32 | 33 | ||
@@ -385,6 +386,17 @@ function once(callback) { | |||
| 385 | 386 | }; | |
| 386 | 387 | } | |
| 387 | 388 | ||
| 389 | + let validateUint32; | ||
| 390 | + | ||
| 391 | + function sleep(msec) { | ||
| 392 | + // Lazy-load to avoid a circular dependency. | ||
| 393 | + if (validateUint32 === undefined) | ||
| 394 | + ({ validateUint32 } = require('internal/validators')); | ||
| 395 | + | ||
| 396 | + validateUint32(msec, 'msec'); | ||
| 397 | + _sleep(msec); | ||
| 398 | + } | ||
| 399 | + | ||
| 388 | 400 | module.exports = { | |
| 389 | 401 | assertCrypto, | |
| 390 | 402 | cachedResult, | |
@@ -402,6 +414,7 @@ module.exports = { | |||
| 402 | 414 | normalizeEncoding, | |
| 403 | 415 | once, | |
| 404 | 416 | promisify, | |
| 417 | + sleep, | ||
| 405 | 418 | spliceOne, | |
| 406 | 419 | removeColors, | |
| 407 | 420 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -169,6 +169,12 @@ static void SetHiddenValue(const FunctionCallbackInfo<Value>& args) { | |||
| 169 | 169 | args.GetReturnValue().Set(maybe_value.FromJust()); | |
| 170 | 170 | } | |
| 171 | 171 | ||
| 172 | + static void Sleep(const FunctionCallbackInfo<Value>& args) { | ||
| 173 | + CHECK(args[0]->IsUint32()); | ||
| 174 | + uint32_t msec = args[0].As<Uint32>()->Value(); | ||
| 175 | + uv_sleep(msec); | ||
| 176 | + } | ||
| 177 | + | ||
| 172 | 178 | void ArrayBufferViewHasBuffer(const FunctionCallbackInfo<Value>& args) { | |
| 173 | 179 | CHECK(args[0]->IsArrayBufferView()); | |
| 174 | 180 | args.GetReturnValue().Set(args[0].As<ArrayBufferView>()->HasBuffer()); | |
@@ -290,6 +296,7 @@ void Initialize(Local<Object> target, | |||
| 290 | 296 | env->SetMethodNoSideEffect(target, "getOwnNonIndexProperties", | |
| 291 | 297 | GetOwnNonIndexProperties); | |
| 292 | 298 | env->SetMethodNoSideEffect(target, "getConstructorName", GetConstructorName); | |
| 299 | + env->SetMethod(target, "sleep", Sleep); | ||
| 293 | 300 | ||
| 294 | 301 | env->SetMethod(target, "arrayBufferViewHasBuffer", ArrayBufferViewHasBuffer); | |
| 295 | 302 | Local<Object> constants = Object::New(env->isolate()); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,19 @@ | |||
| 1 | + // Flags: --expose-internals | ||
| 2 | + 'use strict'; | ||
| 3 | + require('../common'); | ||
| 4 | + const assert = require('assert'); | ||
| 5 | + const { sleep } = require('internal/util'); | ||
| 6 | + | ||
| 7 | + [undefined, null, '', {}, true, false].forEach((value) => { | ||
| 8 | + assert.throws( | ||
| 9 | + () => { sleep(value); }, | ||
| 10 | + /The "msec" argument must be of type number/ | ||
| 11 | + ); | ||
| 12 | + }); | ||
| 13 | + | ||
| 14 | + [-1, 3.14, NaN, 4294967296].forEach((value) => { | ||
| 15 | + assert.throws( | ||
| 16 | + () => { sleep(value); }, | ||
| 17 | + /The value of "msec" is out of range/ | ||
| 18 | + ); | ||
| 19 | + }); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments