11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ci// Test API calls for instance data. 31cb0ef41Sopenharmony_ci 41cb0ef41Sopenharmony_ciconst common = require('../../common'); 51cb0ef41Sopenharmony_ciconst assert = require('assert'); 61cb0ef41Sopenharmony_ci 71cb0ef41Sopenharmony_ciif (module !== require.main) { 81cb0ef41Sopenharmony_ci // When required as a module, run the tests. 91cb0ef41Sopenharmony_ci const test_instance_data = 101cb0ef41Sopenharmony_ci require(`./build/${common.buildType}/test_instance_data`); 111cb0ef41Sopenharmony_ci 121cb0ef41Sopenharmony_ci // Print to stdout when the environment deletes the instance data. This output 131cb0ef41Sopenharmony_ci // is checked by the parent process. 141cb0ef41Sopenharmony_ci test_instance_data.setPrintOnDelete(); 151cb0ef41Sopenharmony_ci 161cb0ef41Sopenharmony_ci // Test that instance data can be accessed from a binding. 171cb0ef41Sopenharmony_ci assert.strictEqual(test_instance_data.increment(), 42); 181cb0ef41Sopenharmony_ci 191cb0ef41Sopenharmony_ci // Test that the instance data can be accessed from a finalizer. 201cb0ef41Sopenharmony_ci test_instance_data.objectWithFinalizer(common.mustCall()); 211cb0ef41Sopenharmony_ci global.gc(); 221cb0ef41Sopenharmony_ci} else { 231cb0ef41Sopenharmony_ci // When launched as a script, run tests in either a child process or in a 241cb0ef41Sopenharmony_ci // worker thread. 251cb0ef41Sopenharmony_ci const requireAs = require('../../common/require-as'); 261cb0ef41Sopenharmony_ci const runOptions = { stdio: ['inherit', 'pipe', 'inherit'] }; 271cb0ef41Sopenharmony_ci 281cb0ef41Sopenharmony_ci function checkOutput(child) { 291cb0ef41Sopenharmony_ci assert.strictEqual(child.status, 0); 301cb0ef41Sopenharmony_ci assert.strictEqual( 311cb0ef41Sopenharmony_ci (child.stdout.toString().split(/\r\n?|\n/) || [])[0], 321cb0ef41Sopenharmony_ci 'deleting addon data'); 331cb0ef41Sopenharmony_ci } 341cb0ef41Sopenharmony_ci 351cb0ef41Sopenharmony_ci // Run tests in a child process. 361cb0ef41Sopenharmony_ci checkOutput(requireAs(__filename, ['--expose-gc'], runOptions, 'child')); 371cb0ef41Sopenharmony_ci 381cb0ef41Sopenharmony_ci // Run tests in a worker thread in a child process. 391cb0ef41Sopenharmony_ci checkOutput(requireAs(__filename, ['--expose-gc'], runOptions, 'worker')); 401cb0ef41Sopenharmony_ci} 41