11cb0ef41Sopenharmony_ci// Flags: --expose-internals --no-warnings
21cb0ef41Sopenharmony_ci'use strict';
31cb0ef41Sopenharmony_ci
41cb0ef41Sopenharmony_ciconst common = require('../common');
51cb0ef41Sopenharmony_ciconst assert = require('assert');
61cb0ef41Sopenharmony_ciconst { internalBinding } = require('internal/test/binding');
71cb0ef41Sopenharmony_ciconst {
81cb0ef41Sopenharmony_ci  observerCounts: counts
91cb0ef41Sopenharmony_ci} = internalBinding('performance');
101cb0ef41Sopenharmony_ciconst {
111cb0ef41Sopenharmony_ci  performance,
121cb0ef41Sopenharmony_ci  PerformanceObserver,
131cb0ef41Sopenharmony_ci  constants
141cb0ef41Sopenharmony_ci} = require('perf_hooks');
151cb0ef41Sopenharmony_ci
161cb0ef41Sopenharmony_ciconst {
171cb0ef41Sopenharmony_ci  NODE_PERFORMANCE_ENTRY_TYPE_GC,
181cb0ef41Sopenharmony_ci  NODE_PERFORMANCE_ENTRY_TYPE_HTTP2,
191cb0ef41Sopenharmony_ci} = constants;
201cb0ef41Sopenharmony_ci
211cb0ef41Sopenharmony_ciassert.strictEqual(counts[NODE_PERFORMANCE_ENTRY_TYPE_GC], 0);
221cb0ef41Sopenharmony_ciassert.strictEqual(counts[NODE_PERFORMANCE_ENTRY_TYPE_HTTP2], 0);
231cb0ef41Sopenharmony_ci
241cb0ef41Sopenharmony_ci{
251cb0ef41Sopenharmony_ci  [1, null, undefined, {}, [], Infinity].forEach((i) => {
261cb0ef41Sopenharmony_ci    assert.throws(
271cb0ef41Sopenharmony_ci      () => new PerformanceObserver(i),
281cb0ef41Sopenharmony_ci      {
291cb0ef41Sopenharmony_ci        code: 'ERR_INVALID_ARG_TYPE',
301cb0ef41Sopenharmony_ci        name: 'TypeError',
311cb0ef41Sopenharmony_ci      }
321cb0ef41Sopenharmony_ci    );
331cb0ef41Sopenharmony_ci  });
341cb0ef41Sopenharmony_ci  const observer = new PerformanceObserver(common.mustNotCall());
351cb0ef41Sopenharmony_ci
361cb0ef41Sopenharmony_ci  [1, 'test'].forEach((input) => {
371cb0ef41Sopenharmony_ci    assert.throws(
381cb0ef41Sopenharmony_ci      () => observer.observe(input),
391cb0ef41Sopenharmony_ci      {
401cb0ef41Sopenharmony_ci        code: 'ERR_INVALID_ARG_TYPE',
411cb0ef41Sopenharmony_ci        name: 'TypeError',
421cb0ef41Sopenharmony_ci        message: 'The "options" argument must be of type object.' +
431cb0ef41Sopenharmony_ci                 common.invalidArgTypeHelper(input)
441cb0ef41Sopenharmony_ci      });
451cb0ef41Sopenharmony_ci  });
461cb0ef41Sopenharmony_ci
471cb0ef41Sopenharmony_ci  [1, null, {}, Infinity].forEach((i) => {
481cb0ef41Sopenharmony_ci    assert.throws(() => observer.observe({ entryTypes: i }),
491cb0ef41Sopenharmony_ci                  {
501cb0ef41Sopenharmony_ci                    code: 'ERR_INVALID_ARG_TYPE',
511cb0ef41Sopenharmony_ci                    name: 'TypeError'
521cb0ef41Sopenharmony_ci                  });
531cb0ef41Sopenharmony_ci  });
541cb0ef41Sopenharmony_ci
551cb0ef41Sopenharmony_ci  const obs = new PerformanceObserver(common.mustNotCall());
561cb0ef41Sopenharmony_ci  obs.observe({ entryTypes: ['mark', 'mark'] });
571cb0ef41Sopenharmony_ci  obs.disconnect();
581cb0ef41Sopenharmony_ci  performance.mark('42');
591cb0ef41Sopenharmony_ci}
601cb0ef41Sopenharmony_ci
611cb0ef41Sopenharmony_ci// Test Non-Buffered
621cb0ef41Sopenharmony_ci{
631cb0ef41Sopenharmony_ci  const observer =
641cb0ef41Sopenharmony_ci    new PerformanceObserver(common.mustCall(callback));
651cb0ef41Sopenharmony_ci
661cb0ef41Sopenharmony_ci  function callback(list, obs) {
671cb0ef41Sopenharmony_ci    assert.strictEqual(obs, observer);
681cb0ef41Sopenharmony_ci    const entries = list.getEntries();
691cb0ef41Sopenharmony_ci    assert.strictEqual(entries.length, 3);
701cb0ef41Sopenharmony_ci    observer.disconnect();
711cb0ef41Sopenharmony_ci  }
721cb0ef41Sopenharmony_ci  observer.observe({ entryTypes: ['mark', 'node'] });
731cb0ef41Sopenharmony_ci  performance.mark('test1');
741cb0ef41Sopenharmony_ci  performance.mark('test2');
751cb0ef41Sopenharmony_ci  performance.mark('test3');
761cb0ef41Sopenharmony_ci}
77