コード例 #1
0
VJSGlobalContext::~VJSGlobalContext()
{
	// Pending fix. (replace with xbox_assert(fContext != NULL)).

	if (fContext != NULL) {

		// require() function object is protected from garbage collection.
		// Unprotect it before the global context is released.

		XBOX::VJSContext	context(fContext);
		XBOX::VJSObject		globalObject(context.GetGlobalObject());
		XBOX::VJSObject		requireObject(context);
		
		requireObject = globalObject.GetPropertyAsObject("require");
		if (requireObject.IsOfClass(VJSRequireClass::Class())) {

			VJSModuleState	*moduleState;

			moduleState = requireObject.GetPrivateData<VJSRequireClass>();
			xbox_assert(moduleState);

			JS4D::UnprotectValue(fContext, moduleState->GetRequireFunctionRef());

		}
	
		JSGlobalContextRelease(fContext);

	}
}
コード例 #2
0
void VJSRequireClass::_CallAsFunction (VJSParms_callAsFunction &ioParms)
{
	XBOX::VString	idString;

	if (!ioParms.GetStringParam(1, idString)) {

		XBOX::vThrowError(XBOX::VE_JVSC_WRONG_PARAMETER_TYPE_STRING, "1");
		return;

	}

	XBOX::VJSContext		context(ioParms.GetContext());
	VJSModuleState			*moduleState;
	XBOX::JS4D::ObjectRef	objectRef;

	if ((moduleState = VJSModuleState::GetModuleState(context)) == NULL
	|| (objectRef = moduleState->GetRequireFunctionRef()) == NULL)

		return;

	XBOX::VJSObject				requireFunction(ioParms.GetContext(), objectRef);
	std::vector<XBOX::VJSValue>	arguments;
	XBOX::VJSValue				result(context);
	XBOX::JS4D::ExceptionRef	exception;

	for (sLONG i = 0; i < ioParms.CountParams(); i++)
		
		arguments.push_back(ioParms.GetParamValue(i + 1));

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

		ioParms.SetException(exception);

	else 

		ioParms.ReturnValue(result);	
}