mirror of
https://github.com/rubyjs/therubyracer
synced 2023-03-27 23:21:42 -04:00
FunctionTemplate, ObjectTemplate, Signature
wrap these three interfaces which are critical for defining v8 functions and calbacks.
This commit is contained in:
parent
e911c4f745
commit
1f70663242
3 changed files with 117 additions and 3 deletions
26
ext/v8/rr.h
26
ext/v8/rr.h
|
@ -69,9 +69,13 @@ public:
|
|||
return (new Holder(handle, Class))->value;
|
||||
}
|
||||
virtual operator v8::Handle<T>() const {
|
||||
Holder* holder = NULL;
|
||||
Data_Get_Struct(this->value, class Holder, holder);
|
||||
return holder->handle;
|
||||
if (RTEST(this->value)) {
|
||||
Holder* holder = NULL;
|
||||
Data_Get_Struct(this->value, class Holder, holder);
|
||||
return holder->handle;
|
||||
} else {
|
||||
return v8::Handle<T>();
|
||||
}
|
||||
}
|
||||
inline v8::Handle<T> operator->() const { return *this;}
|
||||
inline v8::Handle<T> GetHandle() const { return *this;}
|
||||
|
@ -323,15 +327,31 @@ public:
|
|||
inline Array(VALUE value) : Ref<v8::Array>(value) {}
|
||||
};
|
||||
|
||||
class Signature : public Ref<v8::Signature> {
|
||||
static void Init();
|
||||
static VALUE New(int argc, VALUE argv[], VALUE self);
|
||||
|
||||
inline Signature(v8::Handle<v8::Signature> sig) : Ref<v8::Signature>(sig) {}
|
||||
inline Signature(VALUE value) : Ref<v8::Signature>(value) {}
|
||||
};
|
||||
|
||||
class Template {
|
||||
public:
|
||||
static void Init();
|
||||
};
|
||||
|
||||
class ObjectTemplate : public Ref<v8::ObjectTemplate> {
|
||||
public:
|
||||
static void Init();
|
||||
};
|
||||
|
||||
class FunctionTemplate : public Ref<v8::FunctionTemplate> {
|
||||
public:
|
||||
static void Init();
|
||||
static VALUE New(int argc, VALUE argv[], VALUE self);
|
||||
|
||||
inline FunctionTemplate(VALUE value) : Ref<v8::FunctionTemplate>(value) {}
|
||||
inline FunctionTemplate(v8::Handle<v8::FunctionTemplate> t) : Ref<v8::FunctionTemplate>(t) {}
|
||||
};
|
||||
|
||||
class V8 {
|
||||
|
|
16
ext/v8/signature.cc
Normal file
16
ext/v8/signature.cc
Normal file
|
@ -0,0 +1,16 @@
|
|||
#include "rr.h"
|
||||
|
||||
namespace rr {
|
||||
void Signature::Init() {
|
||||
ClassBuilder("Signature").
|
||||
defineMethod("New", &New).
|
||||
store(&Class);
|
||||
}
|
||||
|
||||
VALUE Signature::New(int length, VALUE args[], VALUE self) {
|
||||
VALUE receiver; VALUE argc; VALUE argv;
|
||||
rb_scan_args(length, args, "03", &receiver, &argc, &argv);
|
||||
std::vector< v8::Handle<v8::FunctionTemplate> > parameters(Int(argc));
|
||||
return Signature(v8::Signature::New(FunctionTemplate(receiver), Int(argc), FunctionTemplate::array(argv, parameters)));
|
||||
}
|
||||
}
|
|
@ -3,11 +3,89 @@
|
|||
namespace rr {
|
||||
void Template::Init() {
|
||||
ClassBuilder("Template");
|
||||
ObjectTemplate::Init();
|
||||
FunctionTemplate::Init();
|
||||
}
|
||||
|
||||
void ObjectTemplate::Init() {
|
||||
ClassBuilder("ObjectTemplate", "Template").
|
||||
store(&Class);
|
||||
}
|
||||
|
||||
void FunctionTemplate::Init() {
|
||||
ClassBuilder("FunctionTemplate", "Template").
|
||||
defineMethod("New", &New).
|
||||
store(&Class);
|
||||
}
|
||||
|
||||
VALUE FunctionTemplate::New(int argc, VALUE argv[], VALUE self) {
|
||||
VALUE code; VALUE data; VALUE signature;
|
||||
rb_scan_args(argc, argv, "03", &code, &data, &signature);
|
||||
return FunctionTemplate(v8::FunctionTemplate::New());
|
||||
// InvocationCallback callback(code, data);
|
||||
// return FunctionTemplate(v8::FunctionTemplate::New(callback, callback.data, Signature(signature)));
|
||||
}
|
||||
|
||||
// /** Creates a function template.*/
|
||||
// static Local<FunctionTemplate> New(
|
||||
// InvocationCallback callback = 0,
|
||||
// Handle<Value> data = Handle<Value>(),
|
||||
// Handle<Signature> signature = Handle<Signature>());
|
||||
// /** Returns the unique function instance in the current execution context.*/
|
||||
// Local<Function> GetFunction();
|
||||
//
|
||||
// /**
|
||||
// * Set the call-handler callback for a FunctionTemplate. This
|
||||
// * callback is called whenever the function created from this
|
||||
// * FunctionTemplate is called.
|
||||
// */
|
||||
// void SetCallHandler(InvocationCallback callback,
|
||||
// Handle<Value> data = Handle<Value>());
|
||||
//
|
||||
// /** Get the InstanceTemplate. */
|
||||
// Local<ObjectTemplate> InstanceTemplate();
|
||||
//
|
||||
// /** Causes the function template to inherit from a parent function template.*/
|
||||
// void Inherit(Handle<FunctionTemplate> parent);
|
||||
//
|
||||
// /**
|
||||
// * A PrototypeTemplate is the template used to create the prototype object
|
||||
// * of the function created by this template.
|
||||
// */
|
||||
// Local<ObjectTemplate> PrototypeTemplate();
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * Set the class name of the FunctionTemplate. This is used for
|
||||
// * printing objects created with the function created from the
|
||||
// * FunctionTemplate as its constructor.
|
||||
// */
|
||||
// void SetClassName(Handle<String> name);
|
||||
//
|
||||
// /**
|
||||
// * Determines whether the __proto__ accessor ignores instances of
|
||||
// * the function template. If instances of the function template are
|
||||
// * ignored, __proto__ skips all instances and instead returns the
|
||||
// * next object in the prototype chain.
|
||||
// *
|
||||
// * Call with a value of true to make the __proto__ accessor ignore
|
||||
// * instances of the function template. Call with a value of false
|
||||
// * to make the __proto__ accessor not ignore instances of the
|
||||
// * function template. By default, instances of a function template
|
||||
// * are not ignored.
|
||||
// */
|
||||
// void SetHiddenPrototype(bool value);
|
||||
//
|
||||
// /**
|
||||
// * Sets the ReadOnly flag in the attributes of the 'prototype' property
|
||||
// * of functions created from this FunctionTemplate to true.
|
||||
// */
|
||||
// void ReadOnlyPrototype();
|
||||
//
|
||||
// /**
|
||||
// * Returns true if the given object is an instance of this function
|
||||
// * template.
|
||||
// */
|
||||
// bool HasInstance(Handle<Value> object);
|
||||
|
||||
}
|
Loading…
Reference in a new issue