Skip to content

Commit caca734

Browse files
Jake ChampionJakeChampion
authored andcommitted
allow use of internal_method and create_internal_method from other files by adding them to the header file
we plan to move the built-ins into their own files and they will require access to these functions
1 parent dab23d5 commit caca734

File tree

2 files changed

+23
-21
lines changed

2 files changed

+23
-21
lines changed

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

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -77,27 +77,6 @@ namespace Request {
7777
JSObject *response_promise(JSObject *obj);
7878
}
7979

80-
typedef bool InternalMethod(JSContext *cx, HandleObject receiver, HandleValue extra, CallArgs args);
81-
template <InternalMethod fun> bool internal_method(JSContext *cx, unsigned argc, Value *vp) {
82-
CallArgs args = CallArgsFromVp(argc, vp);
83-
RootedObject self(cx, &js::GetFunctionNativeReserved(&args.callee(), 0).toObject());
84-
RootedValue extra(cx, js::GetFunctionNativeReserved(&args.callee(), 1));
85-
return fun(cx, self, extra, args);
86-
}
87-
88-
template <InternalMethod fun>
89-
JSObject *create_internal_method(JSContext *cx, HandleObject receiver,
90-
HandleValue extra = JS::UndefinedHandleValue,
91-
unsigned int nargs = 0, const char *name = "") {
92-
JSFunction *method = js::NewFunctionWithReserved(cx, internal_method<fun>, 1, 0, name);
93-
if (!method)
94-
return nullptr;
95-
RootedObject method_obj(cx, JS_GetFunctionObject(method));
96-
js::SetFunctionNativeReserved(method_obj, 0, JS::ObjectValue(*receiver));
97-
js::SetFunctionNativeReserved(method_obj, 1, extra);
98-
return method_obj;
99-
}
100-
10180
template <InternalMethod fun>
10281
bool enqueue_internal_method(JSContext *cx, HandleObject receiver,
10382
HandleValue extra = JS::UndefinedHandleValue, unsigned int nargs = 0,

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,29 @@ inline bool ThrowIfNotConstructing(JSContext *cx, const JS::CallArgs &args,
5757

5858
uint8_t *value_to_buffer(JSContext *cx, JS::HandleValue val, const char *val_desc, size_t *len);
5959

60+
typedef bool InternalMethod(JSContext *cx, JS::HandleObject receiver, JS::HandleValue extra,
61+
JS::CallArgs args);
62+
63+
template <InternalMethod fun> bool internal_method(JSContext *cx, unsigned argc, JS::Value *vp) {
64+
JS::CallArgs args = CallArgsFromVp(argc, vp);
65+
JS::RootedObject self(cx, &js::GetFunctionNativeReserved(&args.callee(), 0).toObject());
66+
JS::RootedValue extra(cx, js::GetFunctionNativeReserved(&args.callee(), 1));
67+
return fun(cx, self, extra, args);
68+
}
69+
70+
template <InternalMethod fun>
71+
JSObject *create_internal_method(JSContext *cx, JS::HandleObject receiver,
72+
JS::HandleValue extra = JS::UndefinedHandleValue,
73+
unsigned int nargs = 0, const char *name = "") {
74+
JSFunction *method = js::NewFunctionWithReserved(cx, internal_method<fun>, 1, 0, name);
75+
if (!method)
76+
return nullptr;
77+
JS::RootedObject method_obj(cx, JS_GetFunctionObject(method));
78+
js::SetFunctionNativeReserved(method_obj, 0, JS::ObjectValue(*receiver));
79+
js::SetFunctionNativeReserved(method_obj, 1, extra);
80+
return method_obj;
81+
}
82+
6083
bool hasWizeningFinished();
6184
bool isWizening();
6285
void markWizeningAsFinished();

0 commit comments

Comments
 (0)