Skip to content

Commit 09432fc

Browse files
Jake ChampionJakeChampion
authored andcommitted
Allow TextEncoder to be used as a base class to extend from within application javascript
1 parent 11bd86a commit 09432fc

File tree

2 files changed

+12
-16
lines changed

2 files changed

+12
-16
lines changed

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

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5053,19 +5053,6 @@ namespace Slots {
50535053
enum { Count };
50545054
};
50555055

5056-
JSObject *create(JSContext *cx);
5057-
5058-
bool constructor(JSContext *cx, unsigned argc, Value *vp) {
5059-
CTOR_HEADER("TextEncoder", 0);
5060-
5061-
RootedObject self(cx, create(cx));
5062-
if (!self)
5063-
return false;
5064-
5065-
args.rval().setObject(*self);
5066-
return true;
5067-
}
5068-
50695056
const unsigned ctor_length = 0;
50705057

50715058
bool check_receiver(JSContext *cx, HandleValue receiver, const char *method_name);
@@ -5115,10 +5102,19 @@ bool encoding_get(JSContext *cx, unsigned argc, Value *vp) {
51155102
const JSFunctionSpec methods[] = {JS_FN("encode", encode, 1, JSPROP_ENUMERATE), JS_FS_END};
51165103

51175104
const JSPropertySpec properties[] = {JS_PSG("encoding", encoding_get, JSPROP_ENUMERATE), JS_PS_END};
5118-
5105+
bool constructor(JSContext *cx, unsigned argc, Value *vp);
51195106
CLASS_BOILERPLATE(TextEncoder)
51205107

5121-
JSObject *create(JSContext *cx) { return JS_NewObjectWithGivenProto(cx, &class_, proto_obj); }
5108+
bool constructor(JSContext *cx, unsigned argc, Value *vp) {
5109+
CTOR_HEADER("TextEncoder", 0);
5110+
5111+
RootedObject self(cx, JS_NewObjectForConstructor(cx, &class_, args));
5112+
if (!self)
5113+
return false;
5114+
5115+
args.rval().setObject(*self);
5116+
return true;
5117+
}
51225118
} // namespace TextEncoder
51235119

51245120
namespace TextDecoder {

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
@@ -8,7 +8,7 @@ const builtins = [
88
Dictionary,
99
// Headers,
1010
CacheOverride,
11-
// TextEncoder,
11+
TextEncoder,
1212
TextDecoder,
1313
// URL,
1414
// URLSearchParams,

0 commit comments

Comments
 (0)