forked from bytecodealliance/StarlingMonkey
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathabort-controller.cpp
More file actions
70 lines (49 loc) · 1.54 KB
/
abort-controller.cpp
File metadata and controls
70 lines (49 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include "abort-controller.h"
#include "abort-signal.h"
namespace builtins::web::abort {
const JSFunctionSpec AbortController::static_methods[] = {
JS_FS_END,
};
const JSPropertySpec AbortController::static_properties[] = {
JS_PS_END,
};
const JSFunctionSpec AbortController::methods[] = {
JS_FN("abort", abort, 0, JSPROP_ENUMERATE),
JS_FS_END,
};
const JSPropertySpec AbortController::properties[] = {
JS_PSG("signal", signal_get, JSPROP_ENUMERATE),
JS_PS_END,
};
bool AbortController::signal_get(JSContext *cx, unsigned argc, JS::Value *vp) {
METHOD_HEADER(0);
args.rval().set(JS::GetReservedSlot(self, Slots::Signal));
return true;
}
bool AbortController::abort(JSContext *cx, unsigned argc, JS::Value *vp) {
METHOD_HEADER(0);
RootedValue reason(cx, args.get(0));
RootedObject signal(cx, JS::GetReservedSlot(self, Slots::Signal).toObjectOrNull());
if (!signal) {
return false;
}
return AbortSignal::abort(cx, signal, reason);
}
bool AbortController::constructor(JSContext *cx, unsigned argc, JS::Value *vp) {
CTOR_HEADER("AbortController", 0);
RootedObject self(cx, JS_NewObjectForConstructor(cx, &class_, args));
if (!self) {
return false;
}
RootedObject signal(cx, AbortSignal::create(cx));
if (!signal) {
return false;
}
SetReservedSlot(self, Slots::Signal, JS::ObjectValue(*signal));
args.rval().setObject(*self);
return true;
}
bool AbortController::init_class(JSContext *cx, JS::HandleObject global) {
return init_class_impl(cx, global);
}
} // namespace builtins::web::abort