-
-
Notifications
You must be signed in to change notification settings - Fork 251
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Your Name
committed
May 17, 2024
1 parent
8b15ecc
commit ad69cd2
Showing
5 changed files
with
142 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
/* | ||
* Copyright (C) 2013-2023 Ole André Vadla Ravnås <[email protected]> | ||
* | ||
* Licence: wxWindows Library Licence, Version 3.1 | ||
*/ | ||
|
||
#include "gumv8sampler.h" | ||
#include "gumsampler.h" | ||
#include "gumwallclocksampler.h" | ||
|
||
#include "gumv8macros.h" | ||
#include "gumv8scope.h" | ||
|
||
#define GUMJS_MODULE_NAME Sampler | ||
|
||
using namespace v8; | ||
|
||
GUMJS_DECLARE_CONSTRUCTOR (gumjs_sampler_construct) | ||
GUMJS_DECLARE_FUNCTION (gumjs_sampler_sample) | ||
GUMJS_DECLARE_CONSTRUCTOR (gumjs_wallclock_sampler_construct) | ||
|
||
static const GumV8Function gumjs_sampler_functions[] = | ||
{ | ||
{ "sample", gumjs_sampler_sample }, | ||
|
||
{ NULL, NULL } | ||
}; | ||
|
||
void | ||
_gum_v8_sampler_init (GumV8Sampler * self, | ||
GumV8Core * core, | ||
Local<ObjectTemplate> scope) | ||
{ | ||
auto isolate = core->isolate; | ||
|
||
self->core = core; | ||
|
||
auto module = External::New (isolate, self); | ||
|
||
auto sampler = _gum_v8_create_class ("Sampler", | ||
gumjs_sampler_construct, scope, module, isolate); | ||
_gum_v8_class_add (sampler, gumjs_sampler_functions, module, isolate); | ||
self->sampler = new Global<FunctionTemplate> (isolate, sampler); | ||
|
||
auto wallclock_sampler = _gum_v8_create_class ("WallClockSampler", | ||
gumjs_wallclock_sampler_construct, scope, module, isolate); | ||
wallclock_sampler->Inherit (sampler); | ||
} | ||
|
||
void | ||
_gum_v8_sampler_realize (GumV8Sampler * self) | ||
{ | ||
gum_v8_object_manager_init (&self->objects); | ||
} | ||
|
||
void | ||
_gum_v8_sampler_flush (GumV8Sampler * self) | ||
{ | ||
gum_v8_object_manager_flush (&self->objects); | ||
} | ||
|
||
void | ||
_gum_v8_sampler_dispose (GumV8Sampler * self) | ||
{ | ||
gum_v8_object_manager_free (&self->objects); | ||
} | ||
|
||
void | ||
_gum_v8_sampler_finalize (GumV8Sampler * self) | ||
{ | ||
} | ||
|
||
GUMJS_DEFINE_CONSTRUCTOR (gumjs_sampler_construct) | ||
{ | ||
GumV8Sampler * sampler; | ||
if (!_gum_v8_args_parse (args, "X", &sampler)) | ||
return; | ||
|
||
gum_v8_object_manager_add (&module->objects, wrapper, sampler, module); | ||
} | ||
|
||
GUMJS_DEFINE_CLASS_METHOD (gumjs_sampler_sample, GumSampler) | ||
{ | ||
GumSample sample; | ||
|
||
sample = gum_sampler_sample (self); | ||
|
||
info.GetReturnValue ().Set (_gum_v8_uint64_new (sample, core)); | ||
} | ||
|
||
GUMJS_DEFINE_CONSTRUCTOR (gumjs_wallclock_sampler_construct) | ||
{ | ||
if (!info.IsConstructCall ()) | ||
{ | ||
_gum_v8_throw_ascii_literal (isolate, | ||
"use `new WallClockSampler()` to create a new instance"); | ||
return; | ||
} | ||
|
||
auto sampler = gum_wallclock_sampler_new (); | ||
|
||
gum_v8_object_manager_add (&module->objects, wrapper, sampler, module); | ||
|
||
wrapper->SetAlignedPointerInInternalField (0, sampler); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Copyright (C) 2013-2020 Ole André Vadla Ravnås <[email protected]> | ||
* | ||
* Licence: wxWindows Library Licence, Version 3.1 | ||
*/ | ||
|
||
#ifndef __GUM_V8_SAMPLER_H__ | ||
#define __GUM_V8_SAMPLER_H__ | ||
|
||
#include "gumv8object.h" | ||
|
||
struct GumV8Sampler | ||
{ | ||
GumV8Core * core; | ||
|
||
GumV8ObjectManager objects; | ||
|
||
v8::Global<v8::FunctionTemplate> * sampler; | ||
v8::Global<v8::FunctionTemplate> * wallclock_sampler; | ||
}; | ||
|
||
G_GNUC_INTERNAL void _gum_v8_sampler_init (GumV8Sampler * self, | ||
GumV8Core * core, v8::Local<v8::ObjectTemplate> scope); | ||
G_GNUC_INTERNAL void _gum_v8_sampler_realize (GumV8Sampler * self); | ||
G_GNUC_INTERNAL void _gum_v8_sampler_flush (GumV8Sampler * self); | ||
G_GNUC_INTERNAL void _gum_v8_sampler_dispose (GumV8Sampler * self); | ||
G_GNUC_INTERNAL void _gum_v8_sampler_finalize (GumV8Sampler * self); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters