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