Skip to content

Commit a393e07

Browse files
JakeChampionJake Champion
andauthored
refactor Env to use the class BuiltinNoConstructor (#191)
Co-authored-by: Jake Champion <[email protected]>
1 parent 7609a03 commit a393e07

File tree

2 files changed

+23
-12
lines changed

2 files changed

+23
-12
lines changed

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

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11

22
#include "env.h"
3+
namespace builtins {
34

4-
namespace Env {
5-
6-
namespace {
7-
8-
bool env_get(JSContext *cx, unsigned argc, JS::Value *vp) {
5+
bool Env::env_get(JSContext *cx, unsigned argc, JS::Value *vp) {
96
JS::CallArgs args = CallArgsFromVp(argc, vp);
107
if (!args.requireAtLeast(cx, "fastly.env.get", 1))
118
return false;
@@ -23,14 +20,15 @@ bool env_get(JSContext *cx, unsigned argc, JS::Value *vp) {
2320
return true;
2421
}
2522

26-
const JSFunctionSpec methods[] = {JS_FN("get", env_get, 1, JSPROP_ENUMERATE), JS_FS_END};
23+
const JSFunctionSpec Env::methods[] = {JS_FN("get", env_get, 1, JSPROP_ENUMERATE), JS_FS_END};
2724

28-
} // namespace
25+
const JSPropertySpec Env::properties[] = {JS_PS_END};
2926

30-
JSObject *create(JSContext *cx) {
27+
JSObject *Env::create(JSContext *cx) {
3128
JS::RootedObject env(cx, JS_NewPlainObject(cx));
3229
if (!env || !JS_DefineFunctions(cx, env, methods))
3330
return nullptr;
3431
return env;
3532
}
36-
} // namespace Env
33+
34+
} // namespace builtins

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

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,21 @@
33

44
#include "builtin.h"
55

6-
namespace Env {
7-
JSObject *create(JSContext *cx);
8-
}
6+
namespace builtins {
7+
8+
class Env : public BuiltinNoConstructor<Env> {
9+
private:
10+
static bool env_get(JSContext *cx, unsigned argc, JS::Value *vp);
11+
12+
public:
13+
static constexpr const char *class_name = "Env";
14+
15+
static const JSFunctionSpec methods[];
16+
static const JSPropertySpec properties[];
17+
18+
static JSObject *create(JSContext *cx);
19+
};
20+
21+
} // namespace builtins
922

1023
#endif

0 commit comments

Comments
 (0)