Skip to content
This repository was archived by the owner on Dec 4, 2023. It is now read-only.

Commit 638f6ea

Browse files
committed
add docs to the function callback
1 parent 3792d74 commit 638f6ea

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

ext/v8/function-callback.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,17 @@ namespace rr {
1818
return this->container->content[i];
1919
}
2020

21+
/**
22+
* Package up the callback data for this function so that it can
23+
* invoke a Ruby callable.
24+
*
25+
* Each `v8::Function` can have one `v8::Value` associated with it
26+
* that is passed to its `v8::FunctionCallback`. To support this
27+
* same API from ruby, we take the `Value` passed into the
28+
* Function constructor *and* the callback and store them *both*
29+
* in a single `v8::Object` which we use for the C++ level
30+
* callback data.
31+
*/
2132
static v8::Local<v8::Value> wrapData(v8::Isolate* isolate, VALUE r_callback, VALUE r_data) {
2233
v8::Local<v8::Object> holder = v8::Object::New(isolate);
2334
v8::Local<v8::String> callback_key = v8::String::NewFromUtf8(isolate, "rr::callback");
@@ -27,6 +38,14 @@ namespace rr {
2738
return holder;
2839
}
2940

41+
/**
42+
* Call the Ruby code associated with this callback.
43+
*
44+
* Unpack the Ruby code, and the callback data from the C++
45+
* callback data, and then invoke that code.
46+
*
47+
* Note: This function implements the `v8::FunctionCallback` API.
48+
*/
3049
static void invoke(const v8::FunctionCallbackInfo<v8::Value>& info) {
3150
v8::Isolate* isolate = info.GetIsolate();
3251
v8::Local<v8::Object> holder = v8::Local<v8::Object>::Cast<v8::Value>(info.Data());

0 commit comments

Comments
 (0)