| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 5e4aa28 commit 4561cf3
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -8,6 +8,7 @@ namespace util { | |||
| 8 | 8 | ||
| 9 | 9 | using v8::ALL_PROPERTIES; | |
| 10 | 10 | using v8::Array; | |
| 11 | + using v8::ArrayBufferView; | ||
| 11 | 12 | using v8::Boolean; | |
| 12 | 13 | using v8::Context; | |
| 13 | 14 | using v8::Function; | |
@@ -174,6 +175,11 @@ void WatchdogHasPendingSigint(const FunctionCallbackInfo<Value>& args) { | |||
| 174 | 175 | args.GetReturnValue().Set(ret); | |
| 175 | 176 | } | |
| 176 | 177 | ||
| 178 | + void ArrayBufferViewHasBuffer(const FunctionCallbackInfo<Value>& args) { | ||
| 179 | + CHECK(args[0]->IsArrayBufferView()); | ||
| 180 | + args.GetReturnValue().Set(args[0].As<ArrayBufferView>()->HasBuffer()); | ||
| 181 | + } | ||
| 182 | + | ||
| 177 | 183 | void EnqueueMicrotask(const FunctionCallbackInfo<Value>& args) { | |
| 178 | 184 | Environment* env = Environment::GetCurrent(args); | |
| 179 | 185 | Isolate* isolate = env->isolate(); | |
@@ -254,6 +260,7 @@ void Initialize(Local<Object> target, | |||
| 254 | 260 | env->SetMethodNoSideEffect(target, "watchdogHasPendingSigint", | |
| 255 | 261 | WatchdogHasPendingSigint); | |
| 256 | 262 | ||
| 263 | + env->SetMethod(target, "arrayBufferViewHasBuffer", ArrayBufferViewHasBuffer); | ||
| 257 | 264 | env->SetMethod(target, "enqueueMicrotask", EnqueueMicrotask); | |
| 258 | 265 | env->SetMethod(target, "triggerFatalException", FatalException); | |
| 259 | 266 | Local<Object> constants = Object::New(env->isolate()); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,37 @@ | |||
| 1 | + // Flags: --expose-internals | ||
| 2 | + 'use strict'; | ||
| 3 | + require('../common'); | ||
| 4 | + const assert = require('assert'); | ||
| 5 | + const { internalBinding } = require('internal/test/binding'); | ||
| 6 | + const { arrayBufferViewHasBuffer } = internalBinding('util'); | ||
| 7 | + | ||
| 8 | + const tests = [ | ||
| 9 | + { length: 0, expectOnHeap: true }, | ||
| 10 | + { length: 48, expectOnHeap: true }, | ||
| 11 | + { length: 96, expectOnHeap: false }, | ||
| 12 | + { length: 1024, expectOnHeap: false }, | ||
| 13 | + ]; | ||
| 14 | + | ||
| 15 | + for (const { length, expectOnHeap } of tests) { | ||
| 16 | + const arrays = [ | ||
| 17 | + new Uint8Array(length), | ||
| 18 | + new Uint16Array(length / 2), | ||
| 19 | + new Uint32Array(length / 4), | ||
| 20 | + new Float32Array(length / 4), | ||
| 21 | + new Float64Array(length / 8), | ||
| 22 | + Buffer.alloc(length), | ||
| 23 | + Buffer.allocUnsafeSlow(length) | ||
| 24 | + // Buffer.allocUnsafe() is missing because it may use pooled allocations. | ||
| 25 | + ]; | ||
| 26 | + | ||
| 27 | + for (const array of arrays) { | ||
| 28 | + const isOnHeap = !arrayBufferViewHasBuffer(array); | ||
| 29 | + assert.strictEqual(isOnHeap, expectOnHeap, | ||
| 30 | + `mismatch: ${isOnHeap} vs ${expectOnHeap} ` + | ||
| 31 | + `for ${array.constructor.name}, length = ${length}`); | ||
| 32 | + | ||
| 33 | + // Consistency check: Accessing .buffer should create it. | ||
| 34 | + array.buffer; | ||
| 35 | + assert(arrayBufferViewHasBuffer(array)); | ||
| 36 | + } | ||
| 37 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments