xref: /third_party/node/test/addons/non-node-context/test-make-buffer.js
  • Home
  • History
  • Annotate Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
  • only in /third_party/node/test/addons/non-node-context/
11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ci
31cb0ef41Sopenharmony_ciconst common = require('../../common');
41cb0ef41Sopenharmony_ciconst assert = require('assert');
51cb0ef41Sopenharmony_ciconst {
61cb0ef41Sopenharmony_ci  makeBufferInNewContext,
71cb0ef41Sopenharmony_ci} = require(`./build/${common.buildType}/binding`);
81cb0ef41Sopenharmony_ci
91cb0ef41Sopenharmony_ci// Because the `Buffer` function and its protoype property only (currently)
101cb0ef41Sopenharmony_ci// exist in a Node.js instance’s main context, trying to create buffers from
111cb0ef41Sopenharmony_ci// another context throws an exception.
121cb0ef41Sopenharmony_ciassert.throws(
131cb0ef41Sopenharmony_ci  () => makeBufferInNewContext(),
141cb0ef41Sopenharmony_ci  (exception) => {
151cb0ef41Sopenharmony_ci    assert.strictEqual(exception.constructor.name, 'Error');
161cb0ef41Sopenharmony_ci    assert(!(exception.constructor instanceof Error));
171cb0ef41Sopenharmony_ci
181cb0ef41Sopenharmony_ci    assert.strictEqual(exception.code, 'ERR_BUFFER_CONTEXT_NOT_AVAILABLE');
191cb0ef41Sopenharmony_ci    assert.strictEqual(exception.message,
201cb0ef41Sopenharmony_ci                       'Buffer is not available for the current Context');
211cb0ef41Sopenharmony_ci    return true;
221cb0ef41Sopenharmony_ci  },
231cb0ef41Sopenharmony_ci);
24

Indexes created Thu Nov 07 10:32:03 CST 2024