Skip to content
This repository has been archived by the owner on Oct 15, 2020. It is now read-only.

Commit

Permalink
chakrashim: Implemented 2 new nan.h APIs
Browse files Browse the repository at this point in the history
Added below 2 new nan.h APIs of version 2.12
- SetCallHandler
- SetCallAsFunctionHandler

Reviewed-By: @munyirik
  • Loading branch information
kunalspathak committed Oct 19, 2015
1 parent 777a042 commit e4eec51
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
4 changes: 4 additions & 0 deletions deps/chakrashim/include/v8.h
Original file line number Diff line number Diff line change
Expand Up @@ -1794,6 +1794,8 @@ class V8_EXPORT FunctionTemplate : public Template {
Local<ObjectTemplate> PrototypeTemplate();
void SetClassName(Handle<String> name);
void SetHiddenPrototype(bool value);
void SetCallHandler(FunctionCallback callback,
Handle<Value> data = Handle<Value>());
bool HasInstance(Handle<Value> object);
void Inherit(Handle<FunctionTemplate> parent);
};
Expand Down Expand Up @@ -1908,6 +1910,8 @@ class V8_EXPORT ObjectTemplate : public Template {
bool turned_on_by_default = true);

void SetInternalFieldCount(int value);
void SetCallAsFunctionHandler(FunctionCallback callback,
Handle<Value> data = Handle<Value>());

private:
friend struct FunctionCallbackData;
Expand Down
19 changes: 19 additions & 0 deletions deps/chakrashim/src/v8functiontemplate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,25 @@ void FunctionTemplate::SetHiddenPrototype(bool value) {
// CHAKRA-TODO
}

void FunctionTemplate::SetCallHandler(FunctionCallback callback,
Handle<Value> data) {
void* externalData;
if (JsGetExternalData(this, &externalData) != JsNoError) {
return;
}

FunctionCallbackData* callbackData =
new FunctionCallbackData(callback, data, Handle<Signature>());
FunctionTemplateData *functionTemplateData =
reinterpret_cast<FunctionTemplateData*>(externalData);

// delete old callbackData explictly
if (functionTemplateData->callbackData != nullptr) {
delete functionTemplateData->callbackData;
}
functionTemplateData->callbackData = callbackData;
}

bool FunctionTemplate::HasInstance(Handle<Value> object) {
return jsrt::InstanceOf(*object, *GetFunction());
}
Expand Down
24 changes: 24 additions & 0 deletions deps/chakrashim/src/v8objecttemplate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ struct ObjectTemplateData : public TemplateData {
IndexedPropertyDeleterCallback indexedPropertyDeleter;
IndexedPropertyEnumeratorCallback indexedPropertyEnumerator;
Persistent<Value> indexedPropertyInterceptorData;
FunctionCallback functionCallDelegate;
Persistent<Value> functionCallDelegateInterceptorData;
int internalFieldCount;

ObjectTemplateData()
Expand All @@ -52,6 +54,8 @@ struct ObjectTemplateData : public TemplateData {
indexedPropertyQuery(nullptr),
indexedPropertyDeleter(nullptr),
indexedPropertyEnumerator(nullptr),
functionCallDelegate(nullptr),
functionCallDelegateInterceptorData(nullptr),
internalFieldCount(0) {
HandleScope scope(nullptr);
properties = Object::New();
Expand All @@ -68,6 +72,10 @@ struct ObjectTemplateData : public TemplateData {
indexedPropertyGetter != nullptr ||
indexedPropertyQuery != nullptr ||
indexedPropertySetter != nullptr;
/*
CHAKRA: functionCallDelegate is intentionaly not added as interceptors because it can be invoked
through Object::CallAsFunction or Object::CallAsConstructor
*/
}

static void CALLBACK FinalizeCallback(void *data) {
Expand Down Expand Up @@ -1043,6 +1051,22 @@ void ObjectTemplate::SetAccessCheckCallbacks(
// CHAKRA-TODO
}

void ObjectTemplate::SetCallAsFunctionHandler(
FunctionCallback callback,
Handle<Value> data) {
void* externalData;
if (JsGetExternalData(this, &externalData) != JsNoError)
{
return;
}

ObjectTemplateData *objectTemplateData =
reinterpret_cast<ObjectTemplateData*>(externalData);

objectTemplateData->functionCallDelegate = callback;
objectTemplateData->functionCallDelegateInterceptorData = data;
}

void ObjectTemplate::SetInternalFieldCount(int value) {
void* externalData;
if (JsGetExternalData(this, &externalData) != JsNoError) {
Expand Down

0 comments on commit e4eec51

Please sign in to comment.