11cb0ef41Sopenharmony_ci// META: title=Event constructors
21cb0ef41Sopenharmony_ci
31cb0ef41Sopenharmony_citest(function() {
41cb0ef41Sopenharmony_ci  assert_throws_js(
51cb0ef41Sopenharmony_ci    TypeError,
61cb0ef41Sopenharmony_ci    () => Event(""),
71cb0ef41Sopenharmony_ci    "Calling Event constructor without 'new' must throw")
81cb0ef41Sopenharmony_ci})
91cb0ef41Sopenharmony_citest(function() {
101cb0ef41Sopenharmony_ci  assert_throws_js(TypeError, function() {
111cb0ef41Sopenharmony_ci    new Event()
121cb0ef41Sopenharmony_ci  })
131cb0ef41Sopenharmony_ci})
141cb0ef41Sopenharmony_citest(function() {
151cb0ef41Sopenharmony_ci  var test_error = { name: "test" }
161cb0ef41Sopenharmony_ci  assert_throws_exactly(test_error, function() {
171cb0ef41Sopenharmony_ci    new Event({ toString: function() { throw test_error; } })
181cb0ef41Sopenharmony_ci  })
191cb0ef41Sopenharmony_ci})
201cb0ef41Sopenharmony_citest(function() {
211cb0ef41Sopenharmony_ci  var ev = new Event("")
221cb0ef41Sopenharmony_ci  assert_equals(ev.type, "")
231cb0ef41Sopenharmony_ci  assert_equals(ev.target, null)
241cb0ef41Sopenharmony_ci  assert_equals(ev.srcElement, null)
251cb0ef41Sopenharmony_ci  assert_equals(ev.currentTarget, null)
261cb0ef41Sopenharmony_ci  assert_equals(ev.eventPhase, Event.NONE)
271cb0ef41Sopenharmony_ci  assert_equals(ev.bubbles, false)
281cb0ef41Sopenharmony_ci  assert_equals(ev.cancelable, false)
291cb0ef41Sopenharmony_ci  assert_equals(ev.defaultPrevented, false)
301cb0ef41Sopenharmony_ci  assert_equals(ev.returnValue, true)
311cb0ef41Sopenharmony_ci  assert_equals(ev.isTrusted, false)
321cb0ef41Sopenharmony_ci  assert_true(ev.timeStamp > 0)
331cb0ef41Sopenharmony_ci  assert_true("initEvent" in ev)
341cb0ef41Sopenharmony_ci})
351cb0ef41Sopenharmony_citest(function() {
361cb0ef41Sopenharmony_ci  var ev = new Event("test")
371cb0ef41Sopenharmony_ci  assert_equals(ev.type, "test")
381cb0ef41Sopenharmony_ci  assert_equals(ev.target, null)
391cb0ef41Sopenharmony_ci  assert_equals(ev.srcElement, null)
401cb0ef41Sopenharmony_ci  assert_equals(ev.currentTarget, null)
411cb0ef41Sopenharmony_ci  assert_equals(ev.eventPhase, Event.NONE)
421cb0ef41Sopenharmony_ci  assert_equals(ev.bubbles, false)
431cb0ef41Sopenharmony_ci  assert_equals(ev.cancelable, false)
441cb0ef41Sopenharmony_ci  assert_equals(ev.defaultPrevented, false)
451cb0ef41Sopenharmony_ci  assert_equals(ev.returnValue, true)
461cb0ef41Sopenharmony_ci  assert_equals(ev.isTrusted, false)
471cb0ef41Sopenharmony_ci  assert_true(ev.timeStamp > 0)
481cb0ef41Sopenharmony_ci  assert_true("initEvent" in ev)
491cb0ef41Sopenharmony_ci})
501cb0ef41Sopenharmony_citest(function() {
511cb0ef41Sopenharmony_ci  assert_throws_js(TypeError, function() { Event("test") },
521cb0ef41Sopenharmony_ci                   'Calling Event constructor without "new" must throw');
531cb0ef41Sopenharmony_ci})
541cb0ef41Sopenharmony_citest(function() {
551cb0ef41Sopenharmony_ci  var ev = new Event("I am an event", { bubbles: true, cancelable: false})
561cb0ef41Sopenharmony_ci  assert_equals(ev.type, "I am an event")
571cb0ef41Sopenharmony_ci  assert_equals(ev.bubbles, true)
581cb0ef41Sopenharmony_ci  assert_equals(ev.cancelable, false)
591cb0ef41Sopenharmony_ci})
601cb0ef41Sopenharmony_citest(function() {
611cb0ef41Sopenharmony_ci  var ev = new Event("@", { bubblesIGNORED: true, cancelable: true})
621cb0ef41Sopenharmony_ci  assert_equals(ev.type, "@")
631cb0ef41Sopenharmony_ci  assert_equals(ev.bubbles, false)
641cb0ef41Sopenharmony_ci  assert_equals(ev.cancelable, true)
651cb0ef41Sopenharmony_ci})
661cb0ef41Sopenharmony_citest(function() {
671cb0ef41Sopenharmony_ci  var ev = new Event("@", { "bubbles\0IGNORED": true, cancelable: true})
681cb0ef41Sopenharmony_ci  assert_equals(ev.type, "@")
691cb0ef41Sopenharmony_ci  assert_equals(ev.bubbles, false)
701cb0ef41Sopenharmony_ci  assert_equals(ev.cancelable, true)
711cb0ef41Sopenharmony_ci})
721cb0ef41Sopenharmony_citest(function() {
731cb0ef41Sopenharmony_ci  var ev = new Event("Xx", { cancelable: true})
741cb0ef41Sopenharmony_ci  assert_equals(ev.type, "Xx")
751cb0ef41Sopenharmony_ci  assert_equals(ev.bubbles, false)
761cb0ef41Sopenharmony_ci  assert_equals(ev.cancelable, true)
771cb0ef41Sopenharmony_ci})
781cb0ef41Sopenharmony_citest(function() {
791cb0ef41Sopenharmony_ci  var ev = new Event("Xx", {})
801cb0ef41Sopenharmony_ci  assert_equals(ev.type, "Xx")
811cb0ef41Sopenharmony_ci  assert_equals(ev.bubbles, false)
821cb0ef41Sopenharmony_ci  assert_equals(ev.cancelable, false)
831cb0ef41Sopenharmony_ci})
841cb0ef41Sopenharmony_citest(function() {
851cb0ef41Sopenharmony_ci  var ev = new Event("Xx", {bubbles: true, cancelable: false, sweet: "x"})
861cb0ef41Sopenharmony_ci  assert_equals(ev.type, "Xx")
871cb0ef41Sopenharmony_ci  assert_equals(ev.bubbles, true)
881cb0ef41Sopenharmony_ci  assert_equals(ev.cancelable, false)
891cb0ef41Sopenharmony_ci  assert_equals(ev.sweet, undefined)
901cb0ef41Sopenharmony_ci})
911cb0ef41Sopenharmony_citest(function() {
921cb0ef41Sopenharmony_ci  var called = []
931cb0ef41Sopenharmony_ci  var ev = new Event("Xx", {
941cb0ef41Sopenharmony_ci    get cancelable() {
951cb0ef41Sopenharmony_ci      called.push("cancelable")
961cb0ef41Sopenharmony_ci      return false
971cb0ef41Sopenharmony_ci    },
981cb0ef41Sopenharmony_ci    get bubbles() {
991cb0ef41Sopenharmony_ci      called.push("bubbles")
1001cb0ef41Sopenharmony_ci      return true;
1011cb0ef41Sopenharmony_ci    },
1021cb0ef41Sopenharmony_ci    get sweet() {
1031cb0ef41Sopenharmony_ci      called.push("sweet")
1041cb0ef41Sopenharmony_ci      return "x"
1051cb0ef41Sopenharmony_ci    }
1061cb0ef41Sopenharmony_ci  })
1071cb0ef41Sopenharmony_ci  assert_array_equals(called, ["bubbles", "cancelable"])
1081cb0ef41Sopenharmony_ci  assert_equals(ev.type, "Xx")
1091cb0ef41Sopenharmony_ci  assert_equals(ev.bubbles, true)
1101cb0ef41Sopenharmony_ci  assert_equals(ev.cancelable, false)
1111cb0ef41Sopenharmony_ci  assert_equals(ev.sweet, undefined)
1121cb0ef41Sopenharmony_ci})
1131cb0ef41Sopenharmony_citest(function() {
1141cb0ef41Sopenharmony_ci  var ev = new CustomEvent("$", {detail: 54, sweet: "x", sweet2: "x", cancelable:true})
1151cb0ef41Sopenharmony_ci  assert_equals(ev.type, "$")
1161cb0ef41Sopenharmony_ci  assert_equals(ev.bubbles, false)
1171cb0ef41Sopenharmony_ci  assert_equals(ev.cancelable, true)
1181cb0ef41Sopenharmony_ci  assert_equals(ev.sweet, undefined)
1191cb0ef41Sopenharmony_ci  assert_equals(ev.detail, 54)
1201cb0ef41Sopenharmony_ci})
121