summaryrefslogtreecommitdiff
path: root/test/message/console_low_stack_space.js
blob: 4834ffd9cd0b369d88ce09528156d09866165cf0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
'use strict';
// Copy console accessor because requiring ../common touches it
const consoleDescriptor = Object.getOwnPropertyDescriptor(global, 'console');
Object.defineProperty(global, 'console', {
  configurable: true,
  writable: true,
  value: {}
});

require('../common');

// This test checks that, if Node cannot put together the `console` object
// because it is low on stack space while doing so, it can succeed later
// once the stack has unwound a little, and `console` is in a usable state then.

let compiledConsole;

function a() {
  try {
    return a();
  } catch (e) {
    compiledConsole = consoleDescriptor.value;
    if (compiledConsole.log) {
      // Using `console.log` itself might not succeed yet, but the code for it
      // has been compiled.
    } else {
      throw e;
    }
  }
}

a();

compiledConsole.log('Hello, World!');