• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2const common = require('../common');
3
4common.disableCrashOnUnhandledRejection();
5
6const expectedDeprecationWarning = ['Unhandled promise rejections are ' +
7                                   'deprecated. In the future, promise ' +
8                                   'rejections that are not handled will ' +
9                                   'terminate the Node.js process with a ' +
10                                   'non-zero exit code.', 'DEP0018'];
11const expectedPromiseWarning = ['Unhandled promise rejection. ' +
12  'This error originated either by throwing ' +
13  'inside of an async function without a catch ' +
14  'block, or by rejecting a promise which was ' +
15  'not handled with .catch(). To terminate the ' +
16  'node process on unhandled promise rejection, ' +
17  'use the CLI flag `--unhandled-rejections=strict` (see ' +
18  'https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). ' +
19  '(rejection id: 1)'];
20
21function throwErr() {
22  throw new Error('Error from proxy');
23}
24
25const thorny = new Proxy({}, {
26  getPrototypeOf: throwErr,
27  setPrototypeOf: throwErr,
28  isExtensible: throwErr,
29  preventExtensions: throwErr,
30  getOwnPropertyDescriptor: throwErr,
31  defineProperty: throwErr,
32  has: throwErr,
33  get: throwErr,
34  set: throwErr,
35  deleteProperty: throwErr,
36  ownKeys: throwErr,
37  apply: throwErr,
38  construct: throwErr
39});
40
41common.expectWarning({
42  DeprecationWarning: expectedDeprecationWarning,
43  UnhandledPromiseRejectionWarning: expectedPromiseWarning,
44});
45
46// Ensure this doesn't crash
47Promise.reject(thorny);
48