Skip to content

Commit 5f16d89

Browse files
Jake ChampionJakeChampion
authored andcommitted
Allow CacheOverride to be used as a base class to extend from within application javascript
1 parent 3288e8c commit 5f16d89

File tree

2 files changed

+16
-21
lines changed

2 files changed

+16
-21
lines changed

c-dependencies/js-compute-runtime/js-compute-builtins.cpp

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3899,14 +3899,24 @@ template <auto accessor_fn> bool accessor_set(JSContext *cx, unsigned argc, Valu
38993899

39003900
const unsigned ctor_length = 1;
39013901

3902-
JSObject *create(JSContext *cx);
3902+
const JSFunctionSpec methods[] = {JS_FS_END};
3903+
3904+
const JSPropertySpec properties[] = {
3905+
JS_PSGS("mode", accessor_get<mode_get>, accessor_set<mode_set>, JSPROP_ENUMERATE),
3906+
JS_PSGS("ttl", accessor_get<ttl_get>, accessor_set<ttl_set>, JSPROP_ENUMERATE),
3907+
JS_PSGS("swr", accessor_get<swr_get>, accessor_set<swr_set>, JSPROP_ENUMERATE),
3908+
JS_PSGS("surrogateKey", accessor_get<surrogate_key_get>, accessor_set<surrogate_key_set>,
3909+
JSPROP_ENUMERATE),
3910+
JS_PSGS("pci", accessor_get<pci_get>, accessor_set<pci_set>, JSPROP_ENUMERATE),
3911+
JS_PS_END};
3912+
3913+
bool constructor(JSContext *cx, unsigned argc, Value *vp);
3914+
CLASS_BOILERPLATE(CacheOverride)
39033915

39043916
bool constructor(JSContext *cx, unsigned argc, Value *vp) {
39053917
CTOR_HEADER("CacheOverride", 1);
39063918

3907-
RootedObject self(cx, create(cx));
3908-
if (!self)
3909-
return false;
3919+
RootedObject self(cx, JS_NewObjectForConstructor(cx, &class_, args));
39103920

39113921
RootedValue val(cx);
39123922
if (!mode_set(cx, self, args[0], &val))
@@ -3943,29 +3953,14 @@ bool constructor(JSContext *cx, unsigned argc, Value *vp) {
39433953
return true;
39443954
}
39453955

3946-
const JSFunctionSpec methods[] = {JS_FS_END};
3947-
3948-
const JSPropertySpec properties[] = {
3949-
JS_PSGS("mode", accessor_get<mode_get>, accessor_set<mode_set>, JSPROP_ENUMERATE),
3950-
JS_PSGS("ttl", accessor_get<ttl_get>, accessor_set<ttl_set>, JSPROP_ENUMERATE),
3951-
JS_PSGS("swr", accessor_get<swr_get>, accessor_set<swr_set>, JSPROP_ENUMERATE),
3952-
JS_PSGS("surrogateKey", accessor_get<surrogate_key_get>, accessor_set<surrogate_key_set>,
3953-
JSPROP_ENUMERATE),
3954-
JS_PSGS("pci", accessor_get<pci_get>, accessor_set<pci_set>, JSPROP_ENUMERATE),
3955-
JS_PS_END};
3956-
3957-
CLASS_BOILERPLATE(CacheOverride)
3958-
3959-
JSObject *create(JSContext *cx) { return JS_NewObjectWithGivenProto(cx, &class_, proto_obj); }
3960-
39613956
/**
39623957
* Clone a CacheOverride instance by copying all its reserved slots.
39633958
*
39643959
* This works because CacheOverride slots only contain primitive values.
39653960
*/
39663961
JSObject *clone(JSContext *cx, HandleObject self) {
39673962
MOZ_ASSERT(is_instance(self));
3968-
RootedObject result(cx, create(cx));
3963+
RootedObject result(cx, JS_NewObjectWithGivenProto(cx, &class_, proto_obj));
39693964
if (!result) {
39703965
return nullptr;
39713966
}

integration-tests/js-compute/fixtures/extend-from-builtins/extend-from-builtins.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const builtins = [
77
// Response,
88
Dictionary,
99
// Headers,
10-
// CacheOverride,
10+
CacheOverride,
1111
// TextEncoder,
1212
// TextDecoder,
1313
// URL,

0 commit comments

Comments
 (0)