interface Event {
};

interface EventTarget {
};

interface EventHandler {
};

interface Error {
};

dictionary EventInit {
};
[SecureContext]
interface Sensor : EventTarget {
  readonly attribute SensorState state;
  readonly attribute SensorReading? reading;
  void start();
  void stop();
  attribute EventHandler onchange;
  attribute EventHandler onactivate;
  attribute EventHandler onerror;
};

dictionary SensorOptions {
  double? frequency;
};

enum SensorState {
  "idle",
  "activating",
  "activated",
  "errored"
};

[SecureContext]
interface SensorReading {
  readonly attribute DOMHighResTimeStamp timeStamp;
};

[SecureContext, Constructor(DOMString type, SensorErrorEventInit errorEventInitDict)]
interface SensorErrorEvent : Event {
  readonly attribute Error error;
};

dictionary SensorErrorEventInit : EventInit {
  required Error error;
};

[Constructor(optional SensorOptions sensorOptions)]
interface Magnetometer : Sensor {
  readonly attribute MagnetometerReading? reading;
};

[Constructor(MagnetometerReadingInit magnetometerReadingInit)]
interface MagnetometerReading : SensorReading {
    readonly attribute double x;
    readonly attribute double y;
    readonly attribute double z;
};

dictionary MagnetometerReadingInit {
  double x = 0;
  double y = 0;
  double z = 0;
};