Skip to content

Commit 3288e8c

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

File tree

2 files changed

+16
-26
lines changed

2 files changed

+16
-26
lines changed

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

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4996,21 +4996,6 @@ DictionaryHandle dictionary_handle(JSObject *obj) {
49964996
return DictionaryHandle{static_cast<uint32_t>(val.toInt32())};
49974997
}
49984998

4999-
JSObject *create(JSContext *cx, const char *name, size_t name_len);
5000-
5001-
bool constructor(JSContext *cx, unsigned argc, Value *vp) {
5002-
REQUEST_HANDLER_ONLY("The Dictionary builtin");
5003-
CTOR_HEADER("Dictionary", 1);
5004-
5005-
size_t name_len;
5006-
UniqueChars name = encode(cx, args[0], &name_len);
5007-
RootedObject dictionary(cx, create(cx, name.get(), name_len));
5008-
if (!dictionary)
5009-
return false;
5010-
args.rval().setObject(*dictionary);
5011-
return true;
5012-
}
5013-
50144999
const unsigned ctor_length = 1;
50155000

50165001
bool check_receiver(JSContext *cx, HandleValue receiver, const char *method_name);
@@ -5046,20 +5031,25 @@ bool get(JSContext *cx, unsigned argc, Value *vp) {
50465031
const JSFunctionSpec methods[] = {JS_FN("get", get, 1, JSPROP_ENUMERATE), JS_FS_END};
50475032

50485033
const JSPropertySpec properties[] = {JS_PS_END};
5049-
5034+
bool constructor(JSContext *cx, unsigned argc, Value *vp);
50505035
CLASS_BOILERPLATE(Dictionary)
50515036

5052-
JSObject *create(JSContext *cx, const char *name, size_t name_len) {
5053-
RootedObject dict(cx, JS_NewObjectWithGivenProto(cx, &class_, proto_obj));
5054-
if (!dict)
5055-
return nullptr;
5056-
DictionaryHandle dict_handle = {INVALID_HANDLE};
5057-
if (!HANDLE_RESULT(cx, xqd_dictionary_open(name, name_len, &dict_handle)))
5058-
return nullptr;
5037+
bool constructor(JSContext *cx, unsigned argc, Value *vp) {
5038+
REQUEST_HANDLER_ONLY("The Dictionary builtin");
5039+
CTOR_HEADER("Dictionary", 1);
50595040

5060-
JS::SetReservedSlot(dict, Slots::Dictionary, JS::Int32Value((int)dict_handle.handle));
5041+
size_t name_len;
5042+
UniqueChars name = encode(cx, args[0], &name_len);
5043+
RootedObject dictionary(cx, JS_NewObjectForConstructor(cx, &class_, args));
5044+
DictionaryHandle dict_handle = {INVALID_HANDLE};
5045+
if (!HANDLE_RESULT(cx, xqd_dictionary_open(name.get(), name_len, &dict_handle)))
5046+
return false;
50615047

5062-
return dict;
5048+
JS::SetReservedSlot(dictionary, Slots::Dictionary, JS::Int32Value((int)dict_handle.handle));
5049+
if (!dictionary)
5050+
return false;
5051+
args.rval().setObject(*dictionary);
5052+
return true;
50635053
}
50645054
} // namespace Dictionary
50655055

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
@@ -5,7 +5,7 @@ const builtins = [
55
CompressionStream,
66
// Request,
77
// Response,
8-
// Dictionary,
8+
Dictionary,
99
// Headers,
1010
// CacheOverride,
1111
// TextEncoder,

0 commit comments

Comments
 (0)