Skip to content
Merged
9 changes: 0 additions & 9 deletions builtins/web/blob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -417,15 +417,6 @@ Blob::LineEndings Blob::line_endings(JSObject *self) {
JS::GetReservedSlot(self, static_cast<size_t>(Blob::Slots::Endings)).toInt32());
}

bool Blob::is_instance(const JSObject *obj) {
return obj != nullptr &&
(JS::GetClass(obj) == &Blob::class_ || JS::GetClass(obj) == &File::class_);
}

bool Blob::is_instance(const Value val) {
return val.isObject() && is_instance(&val.toObject());
}

bool Blob::append_value(JSContext *cx, HandleObject self, HandleValue val) {
auto blob = Blob::blob(self);

Expand Down
3 changes: 0 additions & 3 deletions builtins/web/blob.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include "builtin.h"
#include "extension-api.h"
#include "js/AllocPolicy.h"
#include "js/TypeDecls.h"
#include "js/Vector.h"

namespace builtins {
Expand Down Expand Up @@ -46,8 +45,6 @@ class Blob : public FinalizableBuiltinImpl<Blob> {
static JSString *type(JSObject *self);
static LineEndings line_endings(JSObject *self);

static bool is_instance(const JSObject *obj);
static bool is_instance(const Value val);
static bool append_value(JSContext *cx, HandleObject self, HandleValue val);
static bool init_blob_parts(JSContext *cx, HandleObject self, HandleValue iterable);
static bool init_options(JSContext *cx, HandleObject self, HandleValue opts);
Expand Down
72 changes: 72 additions & 0 deletions builtins/web/event/custom-event.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#include "custom-event.h"

namespace builtins {
namespace web {
namespace event {

const JSFunctionSpec CustomEvent::static_methods[] = {
JS_FS_END,
};

const JSPropertySpec CustomEvent::static_properties[] = {
JS_PS_END,
};

const JSFunctionSpec CustomEvent::methods[] = {
JS_FS_END,
};

const JSPropertySpec CustomEvent::properties[] = {
JS_PSG("detail", CustomEvent::detail_get, JSPROP_ENUMERATE),
JS_STRING_SYM_PS(toStringTag, "CustomEvent", JSPROP_READONLY),
JS_PS_END,
};

bool CustomEvent::detail_get(JSContext *cx, unsigned argc, JS::Value *vp) {
METHOD_HEADER(0);
// TODO: Change this class so that its prototype isn't an instance of the class
if (self == proto_obj) {
return api::throw_error(cx, api::Errors::WrongReceiver, "name get", "CustomEvent");
}

args.rval().set(JS::GetReservedSlot(self, Slots::Detail));
return true;
}

bool CustomEvent::constructor(JSContext *cx, unsigned argc, JS::Value *vp) {
CTOR_HEADER("CustomEvent", 2);

RootedValue type(cx, args.get(0));
RootedValue opts(cx, args.get(1));
RootedValue detail(cx);

RootedObject self(cx, JS_NewObjectForConstructor(cx, &class_, args));
if (!self) {
return false;
}

if (!Event::init(cx, self, type, opts)) {
return false;
}

if (opts.isObject()) {
JS::RootedObject obj(cx, &opts.toObject());
if (!JS_GetProperty(cx, obj, "detail", &detail)) {
return false;
}
}

SetReservedSlot(self, Slots::Detail, detail);

args.rval().setObject(*self);
return true;
}

bool CustomEvent::init_class(JSContext *cx, JS::HandleObject global) {
Event::register_subclass(&class_);
return init_class_impl(cx, global, Event::proto_obj);
}

} // namespace event
} // namespace web
} // namespace builtins
36 changes: 36 additions & 0 deletions builtins/web/event/custom-event.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#ifndef BUILTINS_WEB_CUSTOM_EVENT_H_
#define BUILTINS_WEB_CUSTOM_EVENT_H_

#include "builtin.h"
#include "event.h"

namespace builtins {
namespace web {
namespace event {

class CustomEvent : public BuiltinImpl<CustomEvent> {
static bool detail_get(JSContext *cx, unsigned argc, JS::Value *vp);

public:
static constexpr int ParentSlots = Event::Slots::Count;
enum Slots { Detail = ParentSlots, Count };

static constexpr const char *class_name = "CustomEvent";
static constexpr unsigned ctor_length = 2;

static const JSFunctionSpec static_methods[];
static const JSPropertySpec static_properties[];
static const JSFunctionSpec methods[];
static const JSPropertySpec properties[];

static JSString *name(JSObject *self);

static bool init_class(JSContext *cx, HandleObject global);
static bool constructor(JSContext *cx, unsigned argc, Value *vp);
};

} // namespace event
} // namespace web
} // namespace builtins

#endif // BUILTINS_WEB_CUSTOM_EVENT_H_
Loading