コード例 #1
0
void
nsXBLProtoImplMethod::Trace(TraceCallback aCallback, void *aClosure) const
{
    if (IsCompiled() && mJSMethodObject) {
        aCallback(nsIProgrammingLanguage::JAVASCRIPT, mJSMethodObject, "mJSMethodObject", aClosure);
    }
}
コード例 #2
0
void
nsXBLProtoImplMethod::Trace(TraceCallback aCallback, void *aClosure) const
{
  if (IsCompiled() && mJSMethodObject) {
    aCallback(mJSMethodObject, "mJSMethodObject", aClosure);
  }
}
コード例 #3
0
	void OpenGLShader::DeleteShader()
	{
		if (!IsCompiled())
			return;

		glDeleteShader(shaderId);
	}
コード例 #4
0
nsXBLProtoImplMethod::~nsXBLProtoImplMethod()
{
    MOZ_COUNT_DTOR(nsXBLProtoImplMethod);

    if (!IsCompiled()) {
        delete GetUncompiledMethod();
    }
}
コード例 #5
0
ファイル: Shader.cpp プロジェクト: opatut/OpenGL-Playground
bool Shader::Compile() const {
    // do not compile twice
    if(IsCompiled())
        return true;

    // set the source
    const char* source = mSource.c_str();
    glShaderSource(mShaderHandle, 1, &source, NULL);

    // compile the shader
    glCompileShader(mShaderHandle);

    // output Log
    _PrintLog();

    return IsCompiled();
}
コード例 #6
0
nsresult
nsXBLProtoImplMethod::InstallMember(nsIScriptContext* aContext,
                                    nsIContent* aBoundElement,
                                    void* aScriptObject,
                                    void* aTargetClassObject,
                                    const nsCString& aClassStr)
{
    NS_PRECONDITION(IsCompiled(),
                    "Should not be installing an uncompiled method");
    JSContext* cx = aContext->GetNativeContext();

    nsIDocument *ownerDoc = aBoundElement->OwnerDoc();
    nsIScriptGlobalObject *sgo;

    if (!(sgo = ownerDoc->GetScopeObject())) {
        return NS_ERROR_UNEXPECTED;
    }

    JSObject * scriptObject = (JSObject *) aScriptObject;
    NS_ASSERTION(scriptObject, "uh-oh, script Object should NOT be null or bad things will happen");
    if (!scriptObject)
        return NS_ERROR_FAILURE;

    JSObject * targetClassObject = (JSObject *) aTargetClassObject;
    JSObject * globalObject = sgo->GetGlobalJSObject();

    // now we want to reevaluate our property using aContext and the script object for this window...
    if (mJSMethodObject && targetClassObject) {
        nsDependentString name(mName);
        JSAutoRequest ar(cx);
        JSAutoEnterCompartment ac;

        if (!ac.enter(cx, globalObject)) {
            return NS_ERROR_UNEXPECTED;
        }

        JSObject * method = ::JS_CloneFunctionObject(cx, mJSMethodObject, globalObject);
        if (!method) {
            return NS_ERROR_OUT_OF_MEMORY;
        }

        if (!::JS_DefineUCProperty(cx, targetClassObject,
                                   reinterpret_cast<const jschar*>(mName),
                                   name.Length(), OBJECT_TO_JSVAL(method),
                                   NULL, NULL, JSPROP_ENUMERATE)) {
            return NS_ERROR_OUT_OF_MEMORY;
        }
    }
    return NS_OK;
}
コード例 #7
0
void
nsXBLProtoImplMethod::AddParameter(const nsAString& aText)
{
    NS_PRECONDITION(!IsCompiled(),
                    "Must not be compiled when accessing uncompiled method");

    nsXBLUncompiledMethod* uncompiledMethod = GetUncompiledMethod();
    if (!uncompiledMethod) {
        uncompiledMethod = new nsXBLUncompiledMethod();
        if (!uncompiledMethod)
            return;
        SetUncompiledMethod(uncompiledMethod);
    }

    uncompiledMethod->AddParameter(aText);
}
コード例 #8
0
void
nsXBLProtoImplMethod::SetLineNumber(PRUint32 aLineNumber)
{
    NS_PRECONDITION(!IsCompiled(),
                    "Must not be compiled when accessing uncompiled method");

    nsXBLUncompiledMethod* uncompiledMethod = GetUncompiledMethod();
    if (!uncompiledMethod) {
        uncompiledMethod = new nsXBLUncompiledMethod();
        if (!uncompiledMethod)
            return;
        SetUncompiledMethod(uncompiledMethod);
    }

    uncompiledMethod->SetLineNumber(aLineNumber);
}
コード例 #9
0
void 
nsXBLProtoImplMethod::AddParameter(const nsAString& aText)
{
  NS_PRECONDITION(!IsCompiled(),
                  "Must not be compiled when accessing uncompiled method");

  if (aText.IsEmpty()) {
    NS_WARNING("Empty name attribute in xbl:parameter!");
    return;
  }

  nsXBLUncompiledMethod* uncompiledMethod = GetUncompiledMethod();
  if (!uncompiledMethod) {
    uncompiledMethod = new nsXBLUncompiledMethod();
    if (!uncompiledMethod)
      return;
    SetUncompiledMethod(uncompiledMethod);
  }

  uncompiledMethod->AddParameter(aText);
}
コード例 #10
0
ファイル: Shader.cpp プロジェクト: apozTrof/shader
bool Shader::CompileSourceFile(const string& aFileName)
{
    //Delete previous shader if the class already contained one.
    if(mShaderId != 0)
    {
        glDeleteShader(mShaderId);
    }

    //Open and read the shader file.
    fstream ShaderFile;
    ShaderFile.open(aFileName.c_str());

    string ShaderCode(  (std::istreambuf_iterator<char>(ShaderFile)), 
                         std::istreambuf_iterator<char>()
                        );

    ShaderFile.close();

    //Create the shader object
    if(mType == Shader_Vertex)
    {
        mShaderId = glCreateShader(GL_VERTEX_SHADER);              
    }
    else if(mType == Shader_Fragment)
    {
        mShaderId = glCreateShader(GL_FRAGMENT_SHADER);
    }
    
    //Associate the shader's source code to the shader object.
    const char* ShaderChars = ShaderCode.c_str();
    glShaderSource(mShaderId,1,&ShaderChars,NULL);
    
    //Compile the shader
    glCompileShader(mShaderId);
      
    mShaderId = mShaderId;

    return IsCompiled();
}
コード例 #11
0
nsresult
nsXBLProtoImplMethod::InstallMember(JSContext* aCx,
                                    JSObject* aTargetClassObject)
{
  NS_PRECONDITION(IsCompiled(),
                  "Should not be installing an uncompiled method");
  MOZ_ASSERT(js::IsObjectInContextCompartment(aTargetClassObject, aCx));

  JSObject* globalObject = JS_GetGlobalForObject(aCx, aTargetClassObject);
  JSObject* scopeObject = xpc::GetXBLScope(aCx, globalObject);

  // now we want to reevaluate our property using aContext and the script object for this window...
  if (mJSMethodObject) {
    nsDependentString name(mName);

    // First, make the function in the compartment of the scope object.
    JSAutoCompartment ac(aCx, scopeObject);
    JSObject * method = ::JS_CloneFunctionObject(aCx, mJSMethodObject, scopeObject);
    if (!method) {
      return NS_ERROR_OUT_OF_MEMORY;
    }

    // Then, enter the content compartment, wrap the method pointer, and define
    // the wrapped version on the class object.
    JSAutoCompartment ac2(aCx, aTargetClassObject);
    if (!JS_WrapObject(aCx, &method) ||
        !::JS_DefineUCProperty(aCx, aTargetClassObject,
                               static_cast<const jschar*>(mName),
                               name.Length(), OBJECT_TO_JSVAL(method),
                               NULL, NULL,
                               JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT)) {
      return NS_ERROR_OUT_OF_MEMORY;
    }
  }
  return NS_OK;
}
コード例 #12
0
nsresult
nsXBLProtoImplAnonymousMethod::Execute(nsIContent* aBoundElement)
{
    NS_PRECONDITION(IsCompiled(), "Can't execute uncompiled method");

    if (!mJSMethodObject) {
        // Nothing to do here
        return NS_OK;
    }

    // Get the script context the same way
    // nsXBLProtoImpl::InstallImplementation does.
    nsIDocument* document = aBoundElement->OwnerDoc();

    nsIScriptGlobalObject* global = document->GetScriptGlobalObject();
    if (!global) {
        return NS_OK;
    }

    nsCOMPtr<nsIScriptContext> context = global->GetContext();
    if (!context) {
        return NS_OK;
    }

    JSContext* cx = context->GetNativeContext();

    JSObject* globalObject = global->GetGlobalJSObject();

    nsCOMPtr<nsIXPConnectJSObjectHolder> wrapper;
    jsval v;
    nsresult rv =
        nsContentUtils::WrapNative(cx, globalObject, aBoundElement, &v,
                                   getter_AddRefs(wrapper));
    NS_ENSURE_SUCCESS(rv, rv);

    JSObject* thisObject = JSVAL_TO_OBJECT(v);

    JSAutoRequest ar(cx);
    JSAutoEnterCompartment ac;

    if (!ac.enter(cx, thisObject))
        return NS_ERROR_UNEXPECTED;

    // Clone the function object, using thisObject as the parent so "this" is in
    // the scope chain of the resulting function (for backwards compat to the
    // days when this was an event handler).
    JSObject* method = ::JS_CloneFunctionObject(cx, mJSMethodObject, thisObject);
    if (!method)
        return NS_ERROR_OUT_OF_MEMORY;

    // Now call the method

    // Use nsCxPusher to make sure we call ScriptEvaluated when we're done.
    nsCxPusher pusher;
    NS_ENSURE_STATE(pusher.Push(aBoundElement));

    // Check whether it's OK to call the method.
    rv = nsContentUtils::GetSecurityManager()->CheckFunctionAccess(cx, method,
            thisObject);

    JSBool ok = JS_TRUE;
    if (NS_SUCCEEDED(rv)) {
        jsval retval;
        ok = ::JS_CallFunctionValue(cx, thisObject, OBJECT_TO_JSVAL(method),
                                    0 /* argc */, nsnull /* argv */, &retval);
    }

    if (!ok) {
        // If a constructor or destructor threw an exception, it doesn't stop
        // anything else.  We just report it.  Note that we need to set aside the
        // frame chain here, since the constructor invocation is not related to
        // whatever is on the stack right now, really.
        JSBool saved = JS_SaveFrameChain(cx);
        JS_ReportPendingException(cx);
        if (saved)
            JS_RestoreFrameChain(cx);
        return NS_ERROR_FAILURE;
    }

    return NS_OK;
}
コード例 #13
0
nsresult
nsXBLProtoImplMethod::CompileMember(nsIScriptContext* aContext, const nsCString& aClassStr,
                                    JSObject* aClassObject)
{
    NS_TIME_FUNCTION_MIN(5);
    NS_PRECONDITION(!IsCompiled(),
                    "Trying to compile an already-compiled method");
    NS_PRECONDITION(aClassObject,
                    "Must have class object to compile");

    nsXBLUncompiledMethod* uncompiledMethod = GetUncompiledMethod();

    // No parameters or body was supplied, so don't install method.
    if (!uncompiledMethod) {
        // Early return after which we consider ourselves compiled.
        mJSMethodObject = nsnull;

        return NS_OK;
    }

    // Don't install method if no name was supplied.
    if (!mName) {
        delete uncompiledMethod;

        // Early return after which we consider ourselves compiled.
        mJSMethodObject = nsnull;

        return NS_OK;
    }

    // We have a method.
    // Allocate an array for our arguments.
    PRInt32 paramCount = uncompiledMethod->GetParameterCount();
    char** args = nsnull;
    if (paramCount > 0) {
        args = new char*[paramCount];
        if (!args)
            return NS_ERROR_OUT_OF_MEMORY;

        // Add our parameters to our args array.
        PRInt32 argPos = 0;
        for (nsXBLParameter* curr = uncompiledMethod->mParameters;
                curr;
                curr = curr->mNext) {
            args[argPos] = curr->mName;
            argPos++;
        }
    }

    // Get the body
    nsDependentString body;
    PRUnichar *bodyText = uncompiledMethod->mBodyText.GetText();
    if (bodyText)
        body.Rebind(bodyText);

    // Now that we have a body and args, compile the function
    // and then define it.
    NS_ConvertUTF16toUTF8 cname(mName);
    nsCAutoString functionUri(aClassStr);
    PRInt32 hash = functionUri.RFindChar('#');
    if (hash != kNotFound) {
        functionUri.Truncate(hash);
    }

    JSObject* methodObject = nsnull;
    nsresult rv = aContext->CompileFunction(aClassObject,
                                            cname,
                                            paramCount,
                                            const_cast<const char**>(args),
                                            body,
                                            functionUri.get(),
                                            uncompiledMethod->mBodyText.GetLineNumber(),
                                            JSVERSION_LATEST,
                                            true,
                                            &methodObject);

    // Destroy our uncompiled method and delete our arg list.
    delete uncompiledMethod;
    delete [] args;
    if (NS_FAILED(rv)) {
        SetUncompiledMethod(nsnull);
        return rv;
    }

    mJSMethodObject = methodObject;

    return NS_OK;
}
コード例 #14
0
ファイル: Shader.cpp プロジェクト: realn/CodeBox
 bool CShader::Compile() {
   glCompileShader(mId);
   CB_GL_CHECKERRORS();
   return IsCompiled();
 }
コード例 #15
0
nsresult 
nsXBLProtoImplMethod::CompileMember(nsIScriptContext* aContext, const nsCString& aClassStr,
                                    JSObject* aClassObject)
{
  NS_PRECONDITION(!IsCompiled(),
                  "Trying to compile an already-compiled method");
  NS_PRECONDITION(aClassObject,
                  "Must have class object to compile");

  nsXBLUncompiledMethod* uncompiledMethod = GetUncompiledMethod();

  // No parameters or body was supplied, so don't install method.
  if (!uncompiledMethod) {
    // Early return after which we consider ourselves compiled.
    mJSMethodObject = nullptr;

    return NS_OK;
  }

  // Don't install method if no name was supplied.
  if (!mName) {
    delete uncompiledMethod;

    // Early return after which we consider ourselves compiled.
    mJSMethodObject = nullptr;

    return NS_OK;
  }

  // We have a method.
  // Allocate an array for our arguments.
  int32_t paramCount = uncompiledMethod->GetParameterCount();
  char** args = nullptr;
  if (paramCount > 0) {
    args = new char*[paramCount];
    if (!args)
      return NS_ERROR_OUT_OF_MEMORY;

    // Add our parameters to our args array.
    int32_t argPos = 0; 
    for (nsXBLParameter* curr = uncompiledMethod->mParameters; 
         curr; 
         curr = curr->mNext) {
      args[argPos] = curr->mName;
      argPos++;
    }
  }

  // Get the body
  nsDependentString body;
  PRUnichar *bodyText = uncompiledMethod->mBodyText.GetText();
  if (bodyText)
    body.Rebind(bodyText);

  // Now that we have a body and args, compile the function
  // and then define it.
  NS_ConvertUTF16toUTF8 cname(mName);
  nsAutoCString functionUri(aClassStr);
  int32_t hash = functionUri.RFindChar('#');
  if (hash != kNotFound) {
    functionUri.Truncate(hash);
  }

  JSObject* methodObject = nullptr;
  JSContext* cx = aContext->GetNativeContext();
  JSAutoRequest ar(cx);
  JSAutoCompartment ac(cx, aClassObject);
  JS::CompileOptions options(cx);
  options.setFileAndLine(functionUri.get(),
                         uncompiledMethod->mBodyText.GetLineNumber())
         .setVersion(JSVERSION_LATEST)
         .setUserBit(true); // Flag us as XBL
  js::RootedObject rootedNull(cx, nullptr); // See bug 781070.
  nsresult rv = nsJSUtils::CompileFunction(cx, rootedNull, options, cname,
                                           paramCount,
                                           const_cast<const char**>(args),
                                           body, &methodObject);

  // Destroy our uncompiled method and delete our arg list.
  delete uncompiledMethod;
  delete [] args;
  if (NS_FAILED(rv)) {
    SetUncompiledMethod(nullptr);
    return rv;
  }

  mJSMethodObject = methodObject;

  return NS_OK;
}