示例#1
0
void ScriptFunction::callCallback(
    const v8::FunctionCallbackInfo<v8::Value>& args) {
  ASSERT(args.Data()->IsExternal());
  ScriptFunction* scriptFunction = static_cast<ScriptFunction*>(
      v8::Local<v8::External>::Cast(args.Data())->Value());
  ScriptValue result = scriptFunction->call(
      ScriptValue(scriptFunction->getScriptState(), args[0]));
  v8SetReturnValue(args, result.v8Value());
}
示例#2
0
void promiseRejectCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
{
    ASSERT(!info.Data().IsEmpty());
    v8::Local<v8::Object> promise = info.Data().As<v8::Object>();
    v8::Local<v8::Value> result = v8::Undefined(info.GetIsolate());
    if (info.Length() > 0)
        result = info[0];

    V8PromiseCustom::reject(promise, result, info.GetIsolate());
}
void ScriptFunction::callCallback(const v8::FunctionCallbackInfo<v8::Value>& args)
{
    v8::Isolate* isolate = args.GetIsolate();
    ASSERT(!args.Data().IsEmpty());
    ScriptFunction* function = ScriptFunction::Cast(args.Data());
    v8::Local<v8::Value> value = args.Length() > 0 ? args[0] : v8::Local<v8::Value>(v8::Undefined(isolate));

    ScriptValue result = function->call(ScriptValue(ScriptState::current(isolate), value));

    v8SetReturnValue(args, result.v8Value());
}
示例#4
0
文件: value.cpp 项目: Doanlmit/PHP-JS
/**
 *  Callback function to be used when invoking functions
 *  defined from the PHP side
 *
 *  @param  info    callback information
 */
static void callback(const v8::FunctionCallbackInfo<v8::Value> &info)
{
    // create a local handle, so properties "fall out of scope"
    v8::HandleScope     scope(Isolate::get());

    // retrieve handle to the original object
    Handle              handle(info.Data());

    // an array to hold all the arguments
    Php::Array arguments;

    // add all the arguments
    for (int i = 0; i < info.Length(); ++i) arguments.set(i, value(info[i]));

    // catch any exceptions the PHP code might throw
    try
    {
        // now execute the function
        Php::Value result(Php::call("call_user_func_array", handle, arguments));

        // cast the value and set it as return parameter
        info.GetReturnValue().Set(value(result));
    }
    catch (const Php::Exception& exception)
    {
        // pass the exception on to javascript userspace
        Isolate::get()->ThrowException(v8::Exception::Error(v8::String::NewFromUtf8(Isolate::get(), exception.what())));
    }
}
static void constructCustomElement(const v8::FunctionCallbackInfo<v8::Value>& info)
{
    v8::Isolate* isolate = info.GetIsolate();

    if (!info.IsConstructCall()) {
        V8ThrowException::throwTypeError(isolate, "DOM object constructor cannot be called as a function.");
        return;
    }

    if (info.Length() > 0) {
        V8ThrowException::throwTypeError(isolate, "This constructor should be called without arguments.");
        return;
    }

    ScriptState* scriptState = ScriptState::current(isolate);
    v8::Local<v8::Object> data = v8::Local<v8::Object>::Cast(info.Data());
    Document* document = V8Document::toImpl(V8HiddenValue::getHiddenValue(scriptState, data, V8HiddenValue::customElementDocument(isolate)).As<v8::Object>());
    TOSTRING_VOID(V8StringResource<>, namespaceURI, V8HiddenValue::getHiddenValue(scriptState, data, V8HiddenValue::customElementNamespaceURI(isolate)));
    TOSTRING_VOID(V8StringResource<>, tagName, V8HiddenValue::getHiddenValue(scriptState, data, V8HiddenValue::customElementTagName(isolate)));
    v8::Local<v8::Value> maybeType = V8HiddenValue::getHiddenValue(scriptState, data, V8HiddenValue::customElementType(isolate));
    TOSTRING_VOID(V8StringResource<>, type, maybeType);

    ExceptionState exceptionState(ExceptionState::ConstructionContext, "CustomElement", info.Holder(), info.GetIsolate());
    V0CustomElementProcessingStack::CallbackDeliveryScope deliveryScope;
    Element* element = document->createElementNS(namespaceURI, tagName, maybeType->IsNull() ? nullAtom : type, exceptionState);
    if (exceptionState.throwIfNeeded())
        return;
    v8SetReturnValueFast(info, element, document);
}
示例#6
0
	void PreludeScript::log_callback(const v8::FunctionCallbackInfo<v8::Value>& args) 
	{
		if (args.Length() != 1)
		{
			args.GetReturnValue().Set(
				v8::Isolate::GetCurrent()->ThrowException(
				v8::Exception::Error(v8::String::NewFromUtf8(v8::Isolate::GetCurrent(), "The 'log' handler expects 1 argument"))));
			return;
		}
		if (args[0].IsEmpty()) 
		{
			args.GetReturnValue().Set(v8::Isolate::GetCurrent()->ThrowException(
				v8::Exception::Error(v8::String::NewFromUtf8(v8::Isolate::GetCurrent(), "The 'log' handler argument cannot be empty"))));
			return;
		}

		// TODO: do we need to check argument data type?

		v8::Handle<v8::External> data = args.Data().As<v8::External>();
		PreludeScript *prelude = reinterpret_cast<PreludeScript *>(data->Value());

		//TODO: make sure correct value type passed
		v8::String::Value message(args[0].As<v8::String>());

		prelude->log_handler(*message);
		args.GetReturnValue().Set(v8::Undefined(v8::Isolate::GetCurrent()));
		return;
	};
示例#7
0
typename std::enable_if<is_function_pointer<F>::value,
	typename function_traits<F>::return_type>::type
invoke(v8::FunctionCallbackInfo<v8::Value> const& args)
{
	F f = get_external_data<F>(args.Data());
	return call_from_v8(std::forward<F>(f), args);
}
void MetadataNode::ClassConstructorCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
{
	try
	{
		SET_PROFILER_FRAME();

		auto thiz = info.This();
		auto node = reinterpret_cast<MetadataNode*>(info.Data().As<External>()->Value());

		Local<Object> outerThis;
		string extendName;
		auto className = node->m_name;

		SetInstanceMetadata(info.GetIsolate(), thiz, node);

		ArgsWrapper argWrapper(info, ArgType::Class, outerThis);

		string fullClassName = CreateFullClassName(className, extendName);
		bool success = NativeScriptRuntime::RegisterInstance(thiz, fullClassName, argWrapper, outerThis, false);
	}
	catch (NativeScriptException& e)
	{
		e.ReThrowToV8();
	}
	catch (std::exception e) {
		stringstream ss;
		ss << "Error: c++ exception: " << e.what() << endl;
		NativeScriptException nsEx(ss.str());
		nsEx.ReThrowToV8();
	}
	catch (...) {
		NativeScriptException nsEx(std::string("Error: c++ exception!"));
		nsEx.ReThrowToV8();
	}
}
示例#9
0
文件: dynprop.cpp 项目: andoma/pdfium
static void FXJSE_V8ProxyCallback_defineProperty(
    const v8::FunctionCallbackInfo<v8::Value>& info) {
  const FXJSE_CLASS* lpClass =
      static_cast<FXJSE_CLASS*>(info.Data().As<v8::External>()->Value());
  if (!lpClass) {
    return;
  }
  v8::Isolate* pIsolate = info.GetIsolate();
  v8::HandleScope scope(pIsolate);
  v8::Local<v8::String> hPropName = info[0]->ToString();
  v8::Local<v8::Object> hPropDescriptor = info[1]->ToObject();
  v8::String::Utf8Value szPropName(hPropName);
  if (!hPropDescriptor->Has(v8::String::NewFromUtf8(pIsolate, "value"))) {
    return;
  }
  v8::Local<v8::Value> hPropValue =
      hPropDescriptor->Get(v8::String::NewFromUtf8(pIsolate, "value"));
  CFX_ByteStringC szFxPropName(*szPropName, szPropName.length());
  CFXJSE_Value* lpThisValue = CFXJSE_Value::Create(info.GetIsolate());
  CFXJSE_Value* lpPropValue = CFXJSE_Value::Create(info.GetIsolate());
  lpThisValue->ForceSetValue(info.This());
  lpPropValue->ForceSetValue(hPropValue);
  FXJSE_DynPropSetterAdapter(
      lpClass, reinterpret_cast<FXJSE_HOBJECT>(lpThisValue), szFxPropName,
      reinterpret_cast<FXJSE_HVALUE>(lpPropValue));
  delete lpThisValue;
  lpThisValue = nullptr;
  delete lpPropValue;
  lpPropValue = nullptr;
}
void MetadataNode::ExtendedClassConstructorCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
{
	SET_PROFILER_FRAME();

	assert(info.IsConstructCall());

	auto isolate = info.GetIsolate();
	auto thiz = info.This();
	auto extData = reinterpret_cast<ExtendedClassData*>(info.Data().As<External>()->Value());

	auto implementationObject = Local<Object>::New(isolate, *extData->implementationObject);

	const auto& extendName = extData->extendedName;
//	auto className = TNS_PREFIX + extData->node->m_name;

	SetInstanceMetadata(isolate, thiz, extData->node);
	thiz->SetInternalField(static_cast<int>(ObjectManager::MetadataNodeKeys::CallSuper), True(isolate));
	thiz->SetHiddenValue(ConvertToV8String("t::implObj"), implementationObject);

	ArgsWrapper argWrapper(info, ArgType::Class, Local<Object>());

//	string fullClassName = CreateFullClassName(className, extendName);
	string fullClassName = extData->fullClassName;

	bool success = NativeScriptRuntime::RegisterInstance(thiz, fullClassName, argWrapper, implementationObject, false);
}
示例#11
0
文件: dynprop.cpp 项目: andoma/pdfium
static void FXJSE_DynPropGetterAdapter_MethodCallback(
    const v8::FunctionCallbackInfo<v8::Value>& info) {
  v8::Local<v8::Object> hCallBackInfo = info.Data().As<v8::Object>();
  FXJSE_CLASS* lpClass = static_cast<FXJSE_CLASS*>(
      hCallBackInfo->GetAlignedPointerFromInternalField(0));
  v8::Local<v8::String> hPropName =
      hCallBackInfo->GetInternalField(1).As<v8::String>();
  ASSERT(lpClass && !hPropName.IsEmpty());
  v8::String::Utf8Value szPropName(hPropName);
  CFX_ByteStringC szFxPropName = *szPropName;
  CFXJSE_Value* lpThisValue = CFXJSE_Value::Create(info.GetIsolate());
  lpThisValue->ForceSetValue(info.This());
  CFXJSE_Value* lpRetValue = CFXJSE_Value::Create(info.GetIsolate());
  CFXJSE_ArgumentsImpl impl = {&info, lpRetValue};
  lpClass->dynMethodCall(reinterpret_cast<FXJSE_HOBJECT>(lpThisValue),
                         szFxPropName,
                         reinterpret_cast<CFXJSE_Arguments&>(impl));
  if (!lpRetValue->DirectGetValue().IsEmpty()) {
    info.GetReturnValue().Set(lpRetValue->DirectGetValue());
  }
  delete lpRetValue;
  lpRetValue = nullptr;
  delete lpThisValue;
  lpThisValue = nullptr;
}
void MetadataNode::InterfaceConstructorCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
{
	SET_PROFILER_FRAME();

	auto thiz = info.This();
	auto node = reinterpret_cast<MetadataNode*>(info.Data().As<External>()->Value());

	Handle<Object> implementationObject;
	Handle<String> v8ExtendName;
	string extendLocation;
	bool extendLocationFound = GetExtendLocation(extendLocation);
	if (info.Length() == 1)
	{
		if (!extendLocationFound)
		{
			ASSERT_FAIL("Invalid extend() call. No name specified for extend. Location: %s", extendLocation.c_str());
		}

		ASSERT_MESSAGE(info[0]->IsObject(), "Invalid extend() call. No implementation object specified. Location: %s", extendLocation.c_str());
		implementationObject = info[0]->ToObject();
	}
	else if (info.Length() == 2)
	{
		ASSERT_MESSAGE(info[0]->IsString(), "Invalid extend() call. No name for extend specified. Location: %s", extendLocation.c_str());
		ASSERT_MESSAGE(info[1]->IsObject(), "Invalid extend() call. Named extend should be called with second object parameter containing overridden methods. Location: %s", extendLocation.c_str());

		DEBUG_WRITE("InterfaceConstructorCallback: getting extend name");
		v8ExtendName = info[0]->ToString();
		implementationObject = info[1]->ToObject();
	}
	else
	{
		ASSERT_FAIL("Invalid extend() call. Location: %s", extendLocation.c_str());
	}

	auto className = node->m_implType;
	auto extendName = ConvertToString(v8ExtendName);
	auto extendNameAndLocation = extendLocation + extendName;
	SetInstanceMetadata(info.GetIsolate(), implementationObject, node);

	//@@@ Refactor
	string fullClassName = CreateFullClassName(className, extendNameAndLocation);
	thiz->SetHiddenValue(ConvertToV8String("implClassName"), ConvertToV8String(fullClassName));
	//

	jclass generatedClass = s_resolveClass(fullClassName, implementationObject);
	implementationObject->SetHiddenValue(ConvertToV8String(fullClassName), External::New(Isolate::GetCurrent(), generatedClass));//

	implementationObject->SetPrototype(thiz->GetPrototype());
	thiz->SetPrototype(implementationObject);
	thiz->SetHiddenValue(ConvertToV8String("t::implObj"), implementationObject);

	ArgsWrapper argWrapper(info, ArgType::Interface, Handle<Object>());

	auto success = s_registerInstance(thiz, fullClassName, argWrapper, implementationObject, true);

	assert(success);
}
示例#13
0
void CallbackInterfaces::VoidPointerCallback(const v8::FunctionCallbackInfo<v8::Value>& args)
{
	Types::CallbackInfoIMPL cb(args);

	v8::Handle<v8::External> ext = v8::Handle<v8::External>::Cast(args.Data());
	Types::VoidPFunction icb = (Types::VoidPFunction)ext->Value();

	args.GetReturnValue().Set((int)icb(cb));
}
void MetadataNode::MethodCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
{
	SET_PROFILER_FRAME();

	auto e = info.Data().As<External>();

	auto callbackData = reinterpret_cast<MethodCallbackData*>(e->Value());

	auto& candidates = callbackData->candidates;

	auto className = callbackData->node->m_name;
	auto methodName = candidates.front().name;

	int argLength = info.Length();
	int count = 0;
	MetadataEntry *entry = nullptr;
	for (auto& c: candidates)
	{
		if (c.paramCount == argLength)
		{
			if (++count > 1)
				break;
			entry = &c;
		}
	}

	auto thiz = info.This();

	auto isSuper = false;
	const auto& first = candidates.front();
	if (!first.isStatic)
	{
		auto extededClassName = thiz->GetHiddenValue(ConvertToV8String("implClassName"));
		isSuper = !extededClassName.IsEmpty();
		if (!isSuper)
		{
			auto superValue = thiz->GetHiddenValue(ConvertToV8String("issupervalue"));
			isSuper = !superValue.IsEmpty();
		}
	}

	// TODO: refactor this
	if (isSuper && (className == "com/tns/NativeScriptActivity"))
	{
		className = "android/app/Activity";
	}

	if ((methodName == V8StringConstants::VALUE_OF) && (argLength == 0))
	{
		info.GetReturnValue().Set(thiz);
	}
	else
	{
		s_callJavaMethod(thiz, className, methodName, entry, first.isStatic, isSuper, info);
	}
}
示例#15
0
AdblockPlus::JsEnginePtr AdblockPlus::JsEngine::FromArguments(const v8::FunctionCallbackInfo<v8::Value>& arguments)
{
  const v8::Local<const v8::External> external =
      v8::Local<const v8::External>::Cast(arguments.Data());
  std::weak_ptr<JsEngine>* data =
      static_cast<std::weak_ptr<JsEngine>*>(external->Value());
  JsEnginePtr result = data->lock();
  if (!result)
    throw std::runtime_error("Oops, our JsEngine is gone, how did that happen?");
  return result;
}
示例#16
0
void CallbackInterfaces::WideStringCallback(const v8::FunctionCallbackInfo<v8::Value>& args)
{
	Types::CallbackInfoIMPL cb(args);

	v8::Handle<v8::External> ext = v8::Handle<v8::External>::Cast(args.Data());
	Types::WideStringFunction icb = (Types::WideStringFunction)ext->Value();

	wchar_t *result = icb(cb);
	v8::Local<v8::String> v8Result = v8::String::NewFromTwoByte(args.GetIsolate(), (uint16_t *)result);

	args.GetReturnValue().Set(v8Result);
}
示例#17
0
void Proxy::onPropertyChanged(const v8::FunctionCallbackInfo<v8::Value>& args)
{
    Isolate* isolate = args.GetIsolate();
    if (args.Length() < 1) {
        JSException::Error(isolate, "Requires property name as first parameters.");
        return;
    }

    Local<String> name = args.Data()->ToString(isolate);
    Local<Value> value = args[0];
    onPropertyChangedForProxy(isolate, name, value, args.Holder());
}
示例#18
0
typename std::enable_if<std::is_member_function_pointer<F>::value,
	typename function_traits<F>::return_type>::type
invoke(v8::FunctionCallbackInfo<v8::Value> const& args)
{
	using arguments = typename function_traits<F>::arguments;
	static_assert(std::tuple_size<arguments>::value > 0, "");
	using class_type = typename std::tuple_element<0, arguments>::type;

	F f = get_external_data<F>(args.Data());
	class_type& obj = from_v8<class_type&>(args.GetIsolate(), args.This());

	return call_from_v8(obj, std::forward<F>(f), args);
}
示例#19
0
void promiseAllFulfillCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
{
    v8::Isolate* isolate = info.GetIsolate();
    ASSERT(!info.Data().IsEmpty());
    v8::Local<v8::Object> environment = info.Data().As<v8::Object>();
    v8::Local<v8::Value> result = v8::Undefined(isolate);
    if (info.Length() > 0)
        result = info[0];

    v8::Local<v8::Object> promise = environment->GetInternalField(V8PromiseCustom::PromiseAllEnvironmentPromiseIndex).As<v8::Object>();
    v8::Local<v8::Object> countdownWrapper = environment->GetInternalField(V8PromiseCustom::PromiseAllEnvironmentCountdownIndex).As<v8::Object>();
    v8::Local<v8::Integer> index = environment->GetInternalField(V8PromiseCustom::PromiseAllEnvironmentIndexIndex).As<v8::Integer>();
    v8::Local<v8::Array> results = environment->GetInternalField(V8PromiseCustom::PromiseAllEnvironmentResultsIndex).As<v8::Array>();

    results->Set(index->Value(), result);

    v8::Local<v8::Integer> countdown = countdownWrapper->GetInternalField(V8PromiseCustom::PrimitiveWrapperPrimitiveIndex).As<v8::Integer>();
    ASSERT(countdown->Value() >= 1);
    if (countdown->Value() == 1) {
        V8PromiseCustom::resolve(promise, results, isolate);
        return;
    }
    countdownWrapper->SetInternalField(V8PromiseCustom::PrimitiveWrapperPrimitiveIndex, v8::Integer::New(isolate, countdown->Value() - 1));
}
示例#20
0
static void JS_PagerOutput(v8::FunctionCallbackInfo<v8::Value> const& args) {
  TRI_V8_TRY_CATCH_BEGIN(isolate);
  v8::HandleScope scope(isolate);

  v8::Local<v8::External> wrap = v8::Local<v8::External>::Cast(args.Data());
  ConsoleFeature* console = static_cast<ConsoleFeature*>(wrap->Value());

  for (int i = 0; i < args.Length(); i++) {
    // extract the next argument
    console->print(TRI_ObjectToString(args[i]));
  }

  TRI_V8_RETURN_UNDEFINED();
  TRI_V8_TRY_CATCH_END
}
void MetadataNode::InnerClassConstructorCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
{
	auto thiz = info.This();
	auto isolate = info.GetIsolate();
	auto data = reinterpret_cast<InnerClassData*>(info.Data().As<External>()->Value());

	auto outerThis = Local<Object>::New(isolate, *data->outerThis);
	string extendName;
	auto className = data->node->m_name;

	SetInstanceMetadata(info.GetIsolate(), thiz, data->node);

	ArgsWrapper argWrapper(info, ArgType::Class, outerThis);

	string fullClassName = CreateFullClassName(className, extendName);
	bool success = NativeScriptRuntime::RegisterInstance(thiz, fullClassName, argWrapper, outerThis, false);
}
示例#22
0
void _json_loader(const v8::FunctionCallbackInfo<v8::Value>& args)
{
    v8::Isolate* isolate = args.GetIsolate();
    obj_ptr<Buffer_base> src = Buffer_base::getInstance(args.Data());

    exlib::string strScript;
    src->toString(strScript);
    v8::Local<v8::Value> v;

    result_t hr = json_base::decode(strScript, v);
    if (hr < 0) {
        ThrowResult(hr);
        return;
    }

    v8::Local<v8::Object> module = v8::Local<v8::Object>::Cast(args[5]);
    module->Set(NewString(isolate, "exports"), v);
}
示例#23
0
    void JSZCluster::constructor(const v8::FunctionCallbackInfo<v8::Value> &info) {
        if (info.IsConstructCall()) {
            return;
        }
        Isolate *isolate = info.GetIsolate();
        try {
            JSZCluster *This = (JSZCluster *) (Local<External>::Cast(info.Data())->Value());
            checkConstructorValidArgument(isolate, info);
            ExtAddress extAddress = getExtAddressFromArg(info, 0);
            EndpointID endpointId(info[1].As<v8::Integer>()->Value());
            ClusterID clusterId(info[2].As<v8::Integer>()->Value());

            info.GetReturnValue().Set(This->createInstance(info.GetIsolate(), extAddress, endpointId, clusterId));
        } catch (std::exception &excp) {
            v8::Local<v8::String> errorMsg = v8::String::NewFromUtf8(isolate, excp.what());
            isolate->ThrowException(errorMsg);
        }
    }
void MetadataNode::ClassConstructorCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
{
	SET_PROFILER_FRAME();

	auto thiz = info.This();
	auto node = reinterpret_cast<MetadataNode*>(info.Data().As<External>()->Value());

	Local<Object> outerThis;
	string extendName;
	auto className = node->m_name;

	SetInstanceMetadata(info.GetIsolate(), thiz, node);

	ArgsWrapper argWrapper(info, ArgType::Class, outerThis);

	string fullClassName = CreateFullClassName(className, extendName);
	bool success = NativeScriptRuntime::RegisterInstance(thiz, fullClassName, argWrapper, outerThis, false);
}
示例#25
0
static void JS_StopOutputPager(
    v8::FunctionCallbackInfo<v8::Value> const& args) {
  TRI_V8_TRY_CATCH_BEGIN(isolate);
  v8::HandleScope scope(isolate);

  v8::Local<v8::External> wrap = v8::Local<v8::External>::Cast(args.Data());
  ConsoleFeature* console = static_cast<ConsoleFeature*>(wrap->Value());

  if (console->pager()) {
    console->print("Stopping pager.\n");
  } else {
    console->print("Pager not running.\n");
  }

  console->setPager(false);

  TRI_V8_RETURN_UNDEFINED();
  TRI_V8_TRY_CATCH_END
}
示例#26
0
static void JS_StartOutputPager(
    v8::FunctionCallbackInfo<v8::Value> const& args) {
  TRI_V8_TRY_CATCH_BEGIN(isolate);
  v8::HandleScope scope(isolate);

  v8::Local<v8::External> wrap = v8::Local<v8::External>::Cast(args.Data());
  ConsoleFeature* console = static_cast<ConsoleFeature*>(wrap->Value());

  if (console->pager()) {
    console->print("Using pager already.\n");
  } else {
    console->setPager(true);
    console->print(std::string(std::string("Using pager ") +
                               console->pagerCommand() +
                               " for output buffering.\n"));
  }

  TRI_V8_RETURN_UNDEFINED();
  TRI_V8_TRY_CATCH_END
}
示例#27
0
void MetadataNode::ExtendedClassConstructorCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
{
	try
	{
		SET_PROFILER_FRAME();

		assert(info.IsConstructCall());

		auto isolate = info.GetIsolate();
		auto thiz = info.This();
		auto extData = reinterpret_cast<ExtendedClassData*>(info.Data().As<External>()->Value());

		auto implementationObject = Local<Object>::New(isolate, *extData->implementationObject);

		const auto& extendName = extData->extendedName;

		SetInstanceMetadata(isolate, thiz, extData->node);
		thiz->SetInternalField(static_cast<int>(ObjectManager::MetadataNodeKeys::CallSuper), True(isolate));
		thiz->SetHiddenValue(ConvertToV8String("t::implObj"), implementationObject);

		ArgsWrapper argWrapper(info, ArgType::Class, Local<Object>());

		string fullClassName = extData->fullClassName;

		bool success = NativeScriptRuntime::RegisterInstance(thiz, fullClassName, argWrapper, implementationObject, false);
	}
	catch (NativeScriptException& e)
	{
		e.ReThrowToV8();
	}
	catch (std::exception e) {
		stringstream ss;
		ss << "Error: c++ exception: " << e.what() << endl;
		NativeScriptException nsEx(ss.str());
		nsEx.ReThrowToV8();
	}
	catch (...) {
		NativeScriptException nsEx(std::string("Error: c++ exception!"));
		nsEx.ReThrowToV8();
	}
}
示例#28
0
void JNIV8ClassInfo::v8MethodCallback(const v8::FunctionCallbackInfo<v8::Value>& args) {
    JNIEnv *env = JNIWrapper::getEnvironment();
    JNILocalFrame localFrame(env);

    HandleScope scope(args.GetIsolate());

    v8::Local<v8::External> ext;

    ext = args.Data().As<v8::External>();
    JNIV8ObjectCallbackHolder* cb = static_cast<JNIV8ObjectCallbackHolder*>(ext->Value());

    if(cb->isStatic) {
        // we do NOT check how this function was invoked.. if a this was supplied, we just ignore it!
        (cb->callback.s)(cb->methodName, args);
    } else {
        ext = args.This()->GetInternalField(0).As<v8::External>();
        JNIV8Object *v8Object = reinterpret_cast<JNIV8Object *>(ext->Value());

        (v8Object->*(cb->callback.i))(cb->methodName, args);
    }
}
示例#29
0
文件: dynprop.cpp 项目: andoma/pdfium
static void FXJSE_V8ProxyCallback_getOwnPropertyDescriptor_setter(
    const v8::FunctionCallbackInfo<v8::Value>& info) {
  v8::Local<v8::Object> hCallBackInfo = info.Data().As<v8::Object>();
  FXJSE_CLASS* lpClass = static_cast<FXJSE_CLASS*>(
      hCallBackInfo->GetAlignedPointerFromInternalField(0));
  v8::Local<v8::String> hPropName =
      hCallBackInfo->GetInternalField(1).As<v8::String>();
  ASSERT(lpClass && !hPropName.IsEmpty());
  v8::String::Utf8Value szPropName(hPropName);
  CFX_ByteStringC szFxPropName = *szPropName;
  CFXJSE_Value* lpThisValue = CFXJSE_Value::Create(info.GetIsolate());
  CFXJSE_Value* lpNewValue = CFXJSE_Value::Create(info.GetIsolate());
  lpThisValue->ForceSetValue(info.This());
  lpNewValue->ForceSetValue(info[0]);
  FXJSE_DynPropSetterAdapter(
      lpClass, reinterpret_cast<FXJSE_HOBJECT>(lpThisValue), szFxPropName,
      reinterpret_cast<FXJSE_HVALUE>(lpNewValue));
  delete lpThisValue;
  lpThisValue = nullptr;
  delete lpNewValue;
  lpNewValue = nullptr;
}
示例#30
0
    void JSZAttribute::constructor(const v8::FunctionCallbackInfo<v8::Value> &info) {
        if (info.IsConstructCall()) {
            return;
        }
        Isolate *isolate = info.GetIsolate();
        try {
            validateParams(info);
            ExtAddress extAddress = getExtAddressFromArg(info);
            EndpointID endpointId(info[1].As<v8::Integer>()->Value());
            ClusterID clusterId(info[2].As<v8::Integer>()->Value());
            uint32_t attributeId = info[3].As<v8::Integer>()->Value();
            JSZAttribute *This = (JSZAttribute *) (Local<External>::Cast(info.Data())->Value());

            std::shared_ptr<ZCLAttribute> zclAttribute = This->getZCLAttribute(extAddress, endpointId, clusterId,
                                                                               attributeId);

            info.GetReturnValue().Set(This->createInstance(isolate, zclAttribute));
        } catch (std::exception &excp) {
            v8::Local<v8::String> errorMsg = v8::String::NewFromUtf8(isolate, excp.what());
            isolate->ThrowException(errorMsg);
        }
    }