コード例 #1
0
ファイル: MyClass_Wrap.cpp プロジェクト: ACEZLY/server
void RegisterMyClass(Isolate* isolate, Local<ObjectTemplate> global)
{
	Local<ObjectTemplate> localTemplate = ObjectTemplate::New(isolate);
	localTemplate->SetInternalFieldCount(1);

	localTemplate->SetAccessor(
		String::NewFromUtf8(isolate, "num", NewStringType::kInternalized)
		.ToLocalChecked(),
		jsMyClassGetNumber,
		jsMyClassSetNumber);
	localTemplate->SetAccessor(
		String::NewFromUtf8(isolate, "name", NewStringType::kInternalized)
		.ToLocalChecked(),
		jsMyClassGetName,
		jsMyClassSetName);
	localTemplate->Set(
		String::NewFromUtf8(isolate, "Method1", NewStringType::kNormal)
		.ToLocalChecked(),
		FunctionTemplate::New(isolate, jsMyClassMethod1));
	localTemplate->Set(
		String::NewFromUtf8(isolate, "Method2", NewStringType::kNormal)
		.ToLocalChecked(),
		FunctionTemplate::New(isolate, jsMyClassMethod2));

	gMyClassTemplate.Reset(isolate, localTemplate);

	global->Set(
		String::NewFromUtf8(isolate, "MyClass", NewStringType::kNormal)
		.ToLocalChecked(),
		FunctionTemplate::New(isolate, jsCreateMyClass));
	global->Set(
		String::NewFromUtf8(isolate, "jsMyFunction", NewStringType::kNormal)
		.ToLocalChecked(),
		FunctionTemplate::New(isolate, jsMyFunction));
	global->Set(
		String::NewFromUtf8(isolate, "jsMyFunction1", NewStringType::kNormal)
		.ToLocalChecked(),
		FunctionTemplate::New(isolate, jsMyFunction1));
	global->Set(
		String::NewFromUtf8(isolate, "jsMyFunction2", NewStringType::kNormal)
		.ToLocalChecked(),
		FunctionTemplate::New(isolate, jsMyFunction2));
}
コード例 #2
0
ファイル: ModuleByteArray.cpp プロジェクト: untik/cwb
void ModuleByteArray::registerTemplates(v8::Isolate* isolate, Local<ObjectTemplate> globalObject)
{
	HandleScope handle_scope(isolate);
	Local<ObjectTemplate> object = ObjectTemplate::New(isolate);

	// Create function template for our constructor it will call the constructByteArray function
	Local<FunctionTemplate> constructorTemplate = FunctionTemplate::New(isolate, constructByteArray);
	constructorTemplate->SetClassName(String::NewFromUtf8(isolate, "ByteArray"));

	// Define function added to each instance
	Local<ObjectTemplate> constructorInstanceTemplate = constructorTemplate->InstanceTemplate();
	constructorInstanceTemplate->SetInternalFieldCount(1);
	constructorInstanceTemplate->Set(String::NewFromUtf8(isolate, "hex"), FunctionTemplate::New(isolate, hex));
	constructorInstanceTemplate->Set(String::NewFromUtf8(isolate, "base64"), FunctionTemplate::New(isolate, base64));
	constructorInstanceTemplate->Set(String::NewFromUtf8(isolate, "hash"), FunctionTemplate::New(isolate, hash));
	constructorInstanceTemplate->Set(String::NewFromUtf8(isolate, "printable"), FunctionTemplate::New(isolate, printable));
	constructorInstanceTemplate->Set(String::NewFromUtf8(isolate, "toString"), FunctionTemplate::New(isolate, toString));

	// Store template
	ByteArrayTemplate.Reset(isolate, constructorInstanceTemplate);

	// Set the function in the global scope -- that is, set "ByteArray" to the constructor
	globalObject->Set(String::NewFromUtf8(isolate, "ByteArray"), constructorTemplate);
}
コード例 #3
0
ファイル: MyClass_Wrap.cpp プロジェクト: ACEZLY/server
void UnregisterMyClass()
{
	gMyClassTemplate.Reset();
}