| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -15,7 +15,8 @@ const { | |||
| 15 | 15 | getHiddenValue, | |
| 16 | 16 | setHiddenValue, | |
| 17 | 17 | arrow_message_private_symbol: kArrowMessagePrivateSymbolIndex, | |
| 18 | - decorated_private_symbol: kDecoratedPrivateSymbolIndex | ||
| 18 | + decorated_private_symbol: kDecoratedPrivateSymbolIndex, | ||
| 19 | + sleep: _sleep | ||
| 19 | 20 | } = internalBinding('util'); | |
| 20 | 21 | const { isNativeError } = internalBinding('types'); | |
| 21 | 22 | ||
@@ -374,6 +375,17 @@ function once(callback) { | |||
| 374 | 375 | }; | |
| 375 | 376 | } | |
| 376 | 377 | ||
| 378 | + let validateUint32; | ||
| 379 | + | ||
| 380 | + function sleep(msec) { | ||
| 381 | + // Lazy-load to avoid a circular dependency. | ||
| 382 | + if (validateUint32 === undefined) | ||
| 383 | + ({ validateUint32 } = require('internal/validators')); | ||
| 384 | + | ||
| 385 | + validateUint32(msec, 'msec'); | ||
| 386 | + _sleep(msec); | ||
| 387 | + } | ||
| 388 | + | ||
| 377 | 389 | module.exports = { | |
| 378 | 390 | assertCrypto, | |
| 379 | 391 | cachedResult, | |
@@ -391,6 +403,7 @@ module.exports = { | |||
| 391 | 403 | normalizeEncoding, | |
| 392 | 404 | once, | |
| 393 | 405 | promisify, | |
| 406 | + sleep, | ||
| 394 | 407 | spliceOne, | |
| 395 | 408 | removeColors, | |
| 396 | 409 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -161,6 +161,12 @@ static void SetHiddenValue(const FunctionCallbackInfo<Value>& args) { | |||
| 161 | 161 | args.GetReturnValue().Set(maybe_value.FromJust()); | |
| 162 | 162 | } | |
| 163 | 163 | ||
| 164 | + static void Sleep(const FunctionCallbackInfo<Value>& args) { | ||
| 165 | + CHECK(args[0]->IsUint32()); | ||
| 166 | + uint32_t msec = args[0].As<Uint32>()->Value(); | ||
| 167 | + uv_sleep(msec); | ||
| 168 | + } | ||
| 169 | + | ||
| 164 | 170 | void ArrayBufferViewHasBuffer(const FunctionCallbackInfo<Value>& args) { | |
| 165 | 171 | CHECK(args[0]->IsArrayBufferView()); | |
| 166 | 172 | args.GetReturnValue().Set(args[0].As<ArrayBufferView>()->HasBuffer()); | |
@@ -282,6 +288,7 @@ void Initialize(Local<Object> target, | |||
| 282 | 288 | env->SetMethodNoSideEffect(target, "getOwnNonIndexProperties", | |
| 283 | 289 | GetOwnNonIndexProperties); | |
| 284 | 290 | env->SetMethodNoSideEffect(target, "getConstructorName", GetConstructorName); | |
| 291 | + env->SetMethod(target, "sleep", Sleep); | ||
| 285 | 292 | ||
| 286 | 293 | env->SetMethod(target, "arrayBufferViewHasBuffer", ArrayBufferViewHasBuffer); | |
| 287 | 294 | 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