@@ -220,6 +220,18 @@ bool Fastly::env_get(JSContext *cx, unsigned argc, JS::Value *vp) {
220220 return true ;
221221}
222222
223+ bool runtime_get_vcpu_time (JSContext *cx, unsigned argc, JS::Value *vp) {
224+ JS::CallArgs args = CallArgsFromVp (argc, vp);
225+ auto res = host_api::Runtime::get_vcpu_ms ();
226+ if (auto *err = res.to_err ()) {
227+ HANDLE_ERROR (cx, *err);
228+ return false ;
229+ }
230+ fprintf (stderr, " GOT: %llu" , res.unwrap ());
231+ args.rval ().setNumber (res.unwrap ());
232+ return true ;
233+ }
234+
223235bool Env::env_get (JSContext *cx, unsigned argc, JS::Value *vp) {
224236 JS::CallArgs args = CallArgsFromVp (argc, vp);
225237 if (!args.requireAtLeast (cx, " fastly.env.get" , 1 ))
@@ -412,6 +424,23 @@ bool install(api::Engine *engine) {
412424 return false ;
413425 }
414426
427+ // fastly:runtime
428+ auto runtime_vcpu_time_get =
429+ JS_NewFunction (engine->cx (), &runtime_get_vcpu_time, 0 , 0 , " vCpuTime" );
430+ RootedObject runtime_vcpu_time_get_obj (engine->cx (), JS_GetFunctionObject (runtime_vcpu_time_get));
431+ RootedValue runtime_vcpu_time_get_val (engine->cx (), ObjectValue (*runtime_vcpu_time_get_obj));
432+ RootedObject runtime_builtin (engine->cx (), JS_NewObject (engine->cx (), nullptr ));
433+ if (!JS_SetProperty (engine->cx (), runtime_builtin, " vCpuTime" , runtime_vcpu_time_get_val)) {
434+ return false ;
435+ }
436+ if (!JS_SetProperty (engine->cx (), fastly, " vCpuTime" , runtime_vcpu_time_get_val)) {
437+ return false ;
438+ }
439+ RootedValue runtime_builtin_val (engine->cx (), JS::ObjectValue (*runtime_builtin));
440+ if (!engine->define_builtin_module (" fastly:runtime" , runtime_builtin_val)) {
441+ return false ;
442+ }
443+
415444 // fastly:experimental
416445 RootedObject experimental (engine->cx (), JS_NewObject (engine->cx (), nullptr ));
417446 RootedValue experimental_val (engine->cx (), JS::ObjectValue (*experimental));
0 commit comments