コード例 #1
0
void InjectedScriptModule::ensureInjected(InjectedScriptManager* injectedScriptManager, InjectedScript injectedScript)
{
    ASSERT(!injectedScript.hasNoValue());
    if (injectedScript.hasNoValue())
        return;

    // FIXME: Make the InjectedScript a module itself.
    Deprecated::ScriptFunctionCall function(injectedScript.injectedScriptObject(), "module", WebCore::functionCallHandlerFromAnyThread);
    function.appendArgument(name());
    bool hadException = false;
    Deprecated::ScriptValue resultValue = injectedScript.callFunctionWithEvalEnabled(function, hadException);
    ASSERT(!hadException);
    if (hadException || resultValue.hasNoValue() || !resultValue.isObject()) {
        Deprecated::ScriptFunctionCall function(injectedScript.injectedScriptObject(), "injectModule", WebCore::functionCallHandlerFromAnyThread);
        function.appendArgument(name());
        function.appendArgument(source());
        function.appendArgument(host(injectedScriptManager, injectedScript.scriptState()));
        resultValue = injectedScript.callFunctionWithEvalEnabled(function, hadException);
        if (hadException || (returnsObject() && (resultValue.hasNoValue() || !resultValue.isObject()))) {
            ASSERT_NOT_REACHED();
            return;
        }
    }

    if (returnsObject()) {
        Deprecated::ScriptObject moduleObject(injectedScript.scriptState(), resultValue);
        initialize(moduleObject, injectedScriptManager->inspectedStateAccessCheck());
    }
}
コード例 #2
0
ファイル: InjectedScriptModule.cpp プロジェクト: boska/webkit
void InjectedScriptModule::ensureInjected(InjectedScriptManager* injectedScriptManager, InjectedScript injectedScript)
{
    ASSERT(!injectedScript.hasNoValue());
    if (injectedScript.hasNoValue())
        return;

    // FIXME: Make the InjectedScript a module itself.
    JSC::APIEntryShim entryShim(injectedScript.scriptState());
    Deprecated::ScriptFunctionCall function(injectedScript.injectedScriptObject(), ASCIILiteral("module"), injectedScriptManager->inspectorEnvironment().functionCallHandler());
    function.appendArgument(name());
    bool hadException = false;
    Deprecated::ScriptValue resultValue = injectedScript.callFunctionWithEvalEnabled(function, hadException);
    ASSERT(!hadException);
    if (hadException || resultValue.hasNoValue() || !resultValue.isObject()) {
        Deprecated::ScriptFunctionCall function(injectedScript.injectedScriptObject(), ASCIILiteral("injectModule"), injectedScriptManager->inspectorEnvironment().functionCallHandler());
        function.appendArgument(name());
        function.appendArgument(source());
        function.appendArgument(host(injectedScriptManager, injectedScript.scriptState()));
        resultValue = injectedScript.callFunctionWithEvalEnabled(function, hadException);
        if (hadException || (returnsObject() && (resultValue.hasNoValue() || !resultValue.isObject()))) {
            ASSERT_NOT_REACHED();
            return;
        }
    }

    if (returnsObject()) {
        Deprecated::ScriptObject moduleObject(injectedScript.scriptState(), resultValue);
        initialize(moduleObject, &injectedScriptManager->inspectorEnvironment());
    }
}
コード例 #3
0
VError VRIAJSCallbackModuleFunction::Call( VJSContext& inContext, const std::vector<VJSValue> *inParameters, VJSValue* outResult)
{
	VError err = VE_OK;

	JS4D::ExceptionRef exception = NULL;
	VJSObject object( inContext.GetGlobalObject());

	VJSValue nameParam( inContext);
	nameParam.SetString( fModuleName);
	std::vector<VJSValue> params;
	params.push_back( nameParam);

	VJSValue module( inContext);
	if (object.CallMemberFunction( L"require", &params, &module, &exception))
	{
		if (!module.IsUndefined() && !module.IsNull())
		{
			VJSObject moduleObject( inContext);
			module.GetObject( moduleObject);
			if (!moduleObject.CallMemberFunction( fFunctionName, inParameters, outResult, &exception))
			{
				JS4D::ThrowVErrorForException( inContext, exception);
				err = VE_RIA_JS_CALL_TO_FUNCTION_FAILED;
			}
		}
		else
		{
			err = VE_RIA_JS_CALL_TO_REQUIRE_FAILED;
		}
	}
	else
	{
		JS4D::ThrowVErrorForException( inContext, exception);
		err = VE_RIA_JS_CALL_TO_REQUIRE_FAILED;
	}

	return err;
}
コード例 #4
0
void VJSRequireClass::_evaluate (VJSParms_callStaticFunction &ioParms, void *)
{
	XBOX::VJSContext	context(ioParms.GetContext());
	XBOX::VString		fullPath;
	XBOX::VJSObject		exportsObject(context), moduleObject(context);

	if (!ioParms.GetStringParam(1, fullPath)) {
		
		XBOX::vThrowError(XBOX::VE_JVSC_WRONG_PARAMETER_TYPE_STRING, "1");
		return;

	}

	if (!ioParms.GetParamObject(2, exportsObject)) {

		XBOX::vThrowError(XBOX::VE_JVSC_WRONG_PARAMETER_TYPE_OBJECT, "2");
		return;

	}

	if (!ioParms.GetParamObject(3, moduleObject)) {

		XBOX::vThrowError(XBOX::VE_JVSC_WRONG_PARAMETER_TYPE_OBJECT, "3");
		return;

	}

	XBOX::VError	error;
	XBOX::VURL		url;
	XBOX::VString	script;
		
	if ((error = VJSModuleState::LoadScript(fullPath, &url, &script)) != XBOX::VE_OK) {

		if (error == XBOX::VE_JVSC_SCRIPT_NOT_FOUND) {

			// Should not happen as require() does already check for existence.

			XBOX::vThrowError(XBOX::VE_JVSC_SCRIPT_NOT_FOUND, fullPath);

		} else

			XBOX::vThrowError(error);
			
	} else {

		XBOX::VFilePath	path(fullPath, FPS_POSIX);
		XBOX::VFile		*file;
			
		if ((file = new XBOX::VFile(path)) == NULL) {

			XBOX::vThrowError(XBOX::VE_MEMORY_FULL);
			
		} else {

			context.GetGlobalObjectPrivateInstance()->RegisterIncludedFile(file);

			XBOX::VString				functionScript;
			XBOX::VJSValue				functionResult(context);
			XBOX::JS4D::ExceptionRef	exception;			

			// Make a function of the module script, then call it.
			
			functionScript.AppendString("(function (exports, module) {");
			functionScript.AppendString(script);
			functionScript.AppendString("})");

			if (!context.EvaluateScript(functionScript, &url, &functionResult, &exception)) {
						
				ioParms.SetException(exception);	// Syntax error.

			} else {

				xbox_assert(functionResult.IsFunction());

				XBOX::VJSObject				functionObject(context);
				std::vector<XBOX::VJSValue>	arguments;
				XBOX::VJSValue				result(context);

				functionObject.SetObjectRef((XBOX::JS4D::ObjectRef) functionResult.GetValueRef());
	
				arguments.push_back(exportsObject);
				arguments.push_back(moduleObject);

				if (!context.GetGlobalObject().CallFunction(functionObject, &arguments, &result, &exception, &path)) 

					ioParms.SetException(exception);

				else 

					ioParms.ReturnValue(result);

			}

			XBOX::ReleaseRefCountable<XBOX::VFile>(&file);

		}

	}	
}