Пример #1
0
url_finalize(JSContext *cx, JSObject *obj)
{
    JSURL *url;
    MochaDecoder *decoder;
    MWContext *context;
    LO_AnchorData *anchor_data;

    url = JS_GetPrivate(cx, obj);
    if (!url)
	return;
    decoder = url->url_decoder;
    if (url->index != URL_NOT_INDEXED) {
	context = decoder->window_context;
	if (context) {
	    LO_LockLayout();
	    anchor_data = LO_GetLinkByIndex(context, url->layer_id, 
                                            url->index);
	    if (anchor_data && anchor_data->mocha_object == obj)
		anchor_data->mocha_object = NULL;
	    LO_UnlockLayout();
	}
    }
    DROP_BACK_COUNT(decoder);
    JS_RemoveRoot(cx, &url->href);
    JS_RemoveRoot(cx, &url->target);
    JS_RemoveRoot(cx, &url->text);
    XP_DELETE(url);
}
Пример #2
0
//---------------------------------------------------------------------------
inline JSBool ejs_throw_error(JSContext *cx, JSObject *obj, const char *msg) {
    JSString *jsstr;

    // if we get errors during error reporting we report those
    if (((jsstr = JS_NewStringCopyZ(cx, msg))) &&
        (JS_AddNamedRoot(cx, &jsstr, "jsstr"))) {
        jsval dummy;
        // We can't use JS_EvaluateScript since the stack would be wrong
        JSFunction *func;
        JSObject   *fobj;
        const char *fbody      = "throw new Error(msg);";
        const char *argnames[] = { "msg" };
        if ((func = JS_CompileFunction(cx, obj, NULL,
                                       1, argnames,
                                       fbody, strlen(fbody),
                                       NULL, 0))) {
            // root function
            if (((fobj = JS_GetFunctionObject(func))) &&
                (JS_AddNamedRoot(cx, &fobj, "fobj"))) {
                jsval args[] = { STRING_TO_JSVAL(jsstr) };
                JS_CallFunction(cx, obj, func, 1, args, &dummy);
                JS_RemoveRoot(cx, &fobj);
            }
        }
        JS_RemoveRoot(cx, &jsstr);
    }

    return JS_FALSE;
}//---------------------------------------------------------------------------
Пример #3
0
static JSBool
enumerate(JSContext *cx, JSObject *obj, JSIterateOp enum_op,
          jsval *statep, jsid *idp)
{
  JSObject *iterator;
 
  switch (enum_op) {
  case JSENUMERATE_INIT:
    if (resolverHasMethod(cx, obj, "enumerate")) {
      if (!delegateToResolver(cx, obj, "enumerate", 0, NULL, statep))
        return JS_FALSE;
      if (!JSVAL_IS_OBJECT(*statep)) {
        JS_ReportError(cx, "Expected enumerate() to return an iterator.");
        return JS_FALSE;
      }
      *idp = JSVAL_ZERO;
      JS_AddRoot(cx, statep);
      return JS_TRUE;
    }
    // TODO: Default behavior?
    JS_ReportError(cx, "Enumeration is not implemented on this object.");
    return JS_FALSE;
  case JSENUMERATE_NEXT:
    jsval rval;
    iterator = JSVAL_TO_OBJECT(*statep);
    if (!JS_CallFunctionName(cx, iterator, "next", 0, NULL, &rval)) {
      if (JS_IsExceptionPending(cx)) {
        jsval exception;
        if (!JS_GetPendingException(cx, &exception))
          return JS_FALSE;
        if (!JSVAL_IS_OBJECT(exception))
          return JS_FALSE;
        JSClass *clasp = JS_GET_CLASS(cx, JSVAL_TO_OBJECT(exception));
        if (clasp &&
            JSCLASS_CACHED_PROTO_KEY(clasp) == JSProto_StopIteration) {
          JS_ClearPendingException(cx);
          *statep = JSVAL_NULL;
          JS_RemoveRoot(cx, statep);
          return JS_TRUE;
        }
      }
      return JS_FALSE;
    }
    if (!JS_ValueToId(cx, rval, idp))
      return JS_FALSE;
    return JS_TRUE;
  case JSENUMERATE_DESTROY:
    JS_RemoveRoot(cx, statep);
    return JS_TRUE;
  default:
    JS_ReportError(cx, "Unknown enum_op");
    return JS_FALSE;
  }
}
Пример #4
0
ScriptInterface::~ScriptInterface()
{
    if (m_Context)
    {
        JS_RemoveRoot(m_Context, &m_OnUpdateFunc);
        JS_RemoveRoot(m_Context, &m_OnRenderFunc);
        JS_RemoveRoot(m_Context, &m_OnBirthFunc);
        JS_RemoveRoot(m_Context, &m_OnDeathFunc);
        JS_RemoveRoot(m_Context, &m_TextureObject);
    }
}
Пример #5
0
/*
 * - Routine used to handle all important initialization.
 * - If 'false' is returned, the interface must not be used.
 */
bool
ScriptInterface::Init(JSContext* context, JSObject* object)
{
    if (!context || !object)
        return false;

    m_Context = context;

    if (!JS_AddRoot(m_Context, &m_OnUpdateFunc))
    {
        m_Context = NULL;
        return false;
    }

    if (!JS_AddRoot(m_Context, &m_OnRenderFunc))
    {
        m_Context = NULL;
        JS_RemoveRoot(m_Context, &m_OnUpdateFunc);
        return false;
    }

    if (!JS_AddRoot(m_Context, &m_OnBirthFunc))
    {
        m_Context = NULL;
        JS_RemoveRoot(m_Context, &m_OnUpdateFunc);
        JS_RemoveRoot(m_Context, &m_OnRenderFunc);
        return false;
    }

    if (!JS_AddRoot(m_Context, &m_OnDeathFunc))
    {
        m_Context = NULL;
        JS_RemoveRoot(m_Context, &m_OnUpdateFunc);
        JS_RemoveRoot(m_Context, &m_OnRenderFunc);
        JS_RemoveRoot(m_Context, &m_OnBirthFunc);
        return false;
    }

    if (!JS_AddRoot(m_Context, &m_TextureObject))
    {
        m_Context = NULL;
        JS_RemoveRoot(m_Context, &m_OnUpdateFunc);
        JS_RemoveRoot(m_Context, &m_OnRenderFunc);
        JS_RemoveRoot(m_Context, &m_OnBirthFunc);
        JS_RemoveRoot(m_Context, &m_OnDeathFunc);
        return false;
    }

    m_Object  = object;

    return true;
}
Пример #6
0
static void
jss_destroy(JSContext *cx, js_setting_t *jss)
{
  LIST_REMOVE(jss, jss_link);
  setting_detach(jss->jss_s);
  JS_RemoveRoot(cx, &jss->jss_obj);
}
Пример #7
0
/* C function bound to a Javascript function of the same name. Called when a prompt
   dialogue is dissmissed */
static JSBool PromptDismiss(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{

	WebcJSDocumentContext *jsmgr = (WebcJSDocumentContext *) jhutil_GetPrivate(cx, obj);
	if (argc > 0)
	{
		JSString *user_input;
		user_input = JS_ValueToString(cx, *argv);
		JS_AddRoot(cx, &user_input);
		WEBC_CHAR *user_string = WEBC_JS_STRING_TO_WEBC_STRING(user_input);
		WebString *user_WebString;
        int user_len = webc_strlen(user_string);
		WEBC_NEW_VERBOSE(user_WebString, WebString(user_len+1),"JsPrompDismissDialog");
		if (user_WebString)
            user_WebString->copy(user_string, user_len+1);
		JS_RemoveRoot(cx, &user_input);

        HTMLDocument *pDoc = (jsmgr)? jsmgr->GetDocument() : 0;
        HDOC_HANDLE doc = (HDOC_HANDLE) pDoc;
        if (doc)
        {
            HBROWSER_HANDLE hbrowser = webc_DocGetBrowser(doc);
            if (hbrowser)
            {
                void* privateData = webc_BrowserGetPrivateData(hbrowser);
                privateData = (void *) user_WebString;
                webc_BrowserSetPrivateData(hbrowser, privateData);
            }
        }
	}
	return (JS_TRUE);
}
Пример #8
0
static JSBool
SetContextObj(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
  nsJSSh* shell;
  if (!GetJSShGlobal(cx, obj, &shell)) return JS_FALSE;

  JSAutoRequest ar(cx);

  if (argc!=1) return JS_FALSE;

  JSObject *arg_obj;
  if (!JS_ValueToObject(cx, argv[0], &arg_obj)) {
    return JS_FALSE;
  }

  if (shell->mContextObj != shell->mGlobal)
    JS_RemoveRoot(cx, &(shell->mContextObj));
  
  shell->mContextObj = arg_obj;
  
  if (shell->mContextObj != shell->mGlobal)
    JS_AddRoot(cx, &(shell->mContextObj));
  
  return JS_TRUE;
}
Пример #9
0
/*
 * Remove the mapping of a JS object from the hash table that maps JS objects
 * to Java objects.  This is called from the finalizer of an instance of
 * netscape.javascript.JSObject.
 */
JSBool
jsj_remove_js_obj_reflection_from_hashtable(JSContext *cx, JSObject *js_obj)
{
    JSHashEntry *he, **hep;
    JSBool success = JS_FALSE;

#ifdef JSJ_THREADSAFE
    PR_EnterMonitor(js_obj_reflections_monitor);
#endif

    /* Get the hash-table entry for this wrapper object */
    hep = JS_HashTableRawLookup(js_obj_reflections, (JSHashNumber)js_obj, js_obj);
    he = *hep;

    JS_ASSERT(he);
    if (he) {
        /* Tell the JS GC that Java no longer keeps a reference to this
           JS object. */
        success = JS_RemoveRoot(cx, (void *)&he->key);

        JS_HashTableRawRemove(js_obj_reflections, hep, he);
    }

#ifdef JSJ_THREADSAFE
    PR_ExitMonitor(js_obj_reflections_monitor);
#endif

    return success;
}
Пример #10
0
void
jsd_RefreshValue(JSDContext* jsdc, JSDValue* jsdval)
{
    JSContext* cx = jsdc->dumbContext;

    if(jsdval->string)
    {
        /* if the jsval is a string, then we didn't need to root the string */
        if(!JSVAL_IS_STRING(jsdval->val))
        {
            JS_BeginRequest(cx);
            JS_RemoveRoot(cx, &jsdval->string);
            JS_EndRequest(cx);
        }
        jsdval->string = NULL;
    }

    jsdval->funName = NULL;
    jsdval->className = NULL;
    DROP_CLEAR_VALUE(jsdc, jsdval->proto);
    DROP_CLEAR_VALUE(jsdc, jsdval->parent);
    DROP_CLEAR_VALUE(jsdc, jsdval->ctor);
    _freeProps(jsdc, jsdval);
    jsdval->flags = 0;
}
Пример #11
0
static void
js_item_eventsub(void *opaque, prop_event_t event, ...)
{
  js_item_t *ji = opaque;
  va_list ap;

  va_start(ap, event);

  switch(event) {
  default:
    break;

  case PROP_DESTROYED:
    js_event_destroy_handlers(ji->ji_model->jm_cx, &ji->ji_event_handlers);
    prop_unsubscribe(ji->ji_eventsub);
    ji->ji_eventsub = NULL;
    ji->ji_model->jm_subs--;
    JS_RemoveRoot(ji->ji_model->jm_cx, &ji->ji_this);
    prop_tag_clear(ji->ji_root, ji->ji_model);
    break;

  case PROP_EXT_EVENT:
    js_event_dispatch(ji->ji_model->jm_cx, &ji->ji_event_handlers,
		      va_arg(ap, event_t *), JSVAL_TO_OBJECT(ji->ji_this));
    break;
  }
  va_end(ap);
}
Пример #12
0
void
ScriptInterface::EndProtection()
{
    JS_RemoveRoot(m_Context, &m_Object);

    m_Protected = false;

}
Пример #13
0
static void
js_subprovider_release(JSContext *cx, js_subprovider_t *sp)
{
  if(atomic_dec(&sp->sp_refcnt))
    return;
  JS_RemoveRoot(cx, &sp->sp_func);
  prop_destroy(sp->sp_title);
  free(sp);
}
Пример #14
0
bool
isCalledForConversion(JSContext * cx, uintN argc, jsval * argv) {
    if (0 < argc && JSVAL_IS_STRING(argv[0])) {
        JSString * myJSString = JSVAL_TO_STRING(argv[0]);
        if (!strcmp(JS_GetStringBytes(myJSString), "CALLED_FROM_AS_JSVAL")) {
            JS_RemoveRoot(cx,&myJSString);
            return true;
        }
    }
    return false;
}
Пример #15
0
void
Function_dealloc(Function* self)
{
    if(self->parent != JSVAL_VOID)
    {
        JS_BeginRequest(self->obj.cx->cx);
        JS_RemoveRoot(self->obj.cx->cx, &(self->parent));
        JS_EndRequest(self->obj.cx->cx);
    }

    ObjectType->tp_dealloc((PyObject*) self);
}
Пример #16
0
void area_finalize(JSContext *cx, JSObject *obj)
{
	myArea* pArea = (myArea*)JS_GetPrivate(cx, obj);

	if(pArea)
	{
		if(pArea->ExitArray)
			JS_RemoveRoot(&pArea->ExitArray);
		JS_SetPrivate(cx, obj, NULL);
		delete pArea;
	}
}
Пример #17
0
void
js_event_destroy_handlers(JSContext *cx, struct js_event_handler_list *list)
{
  js_event_handler_t *jeh;

  while((jeh = LIST_FIRST(list)) != NULL) {
    LIST_REMOVE(jeh, jeh_link);
    JS_RemoveRoot(cx, &jeh->jeh_function);
    free(jeh->jeh_filter);
    free(jeh);
  }
}
Пример #18
0
static void
jsg_destroy(JSContext *cx, js_setting_group_t *jsg)
{
  js_setting_t *jss;
  while((jss = LIST_FIRST(&jsg->jsg_settings)) != NULL)
    jss_destroy(cx, jss);

  prop_unparent(jsg->jsg_root);
  LIST_REMOVE(jsg, jsg_link);
  JS_RemoveRoot(cx, &jsg->jsg_val);
  jsg_release(jsg);
}
Пример #19
0
static void deallocate(JohnsonRuntime* runtime)
{
  JS_RemoveRoot(johnson_get_current_context(runtime), &(runtime->global));
  
  JSContext *context;
  JSContext *iterator = NULL;

  while ((context = JS_ContextIterator(runtime->js, &iterator)) != NULL)
    JS_DestroyContext(context);
  
  JS_DestroyRuntime(runtime->js);
  free(runtime);
}
void TraceMonkeyValue::invalidate()
{
    assert(isValid());

    Logging::log(Logging::INFO, "Removing TM root for %s\r\n", debugName.c_str());

    bool success = JS_RemoveRoot(TraceMonkeyEngine::context, &(this->value)); // Allow GCing (unless others use it)
    assert(success);

    JS_GC(TraceMonkeyEngine::context); // XXX For debugging purposes

    ScriptValue::invalidate(); // call parent
}
ScriptValuePtr TraceMonkeyEngine::createObject()
{
    JSObject* obj = JS_NewObject(context, NULL, NULL, NULL);
    bool success = JS_AddNamedRoot(context, &obj, "TraceMonkeyEngine::createObject temp val"); // Ensure our value won't be GCed
    assert(success);

    ScriptValuePtr ret( new TraceMonkeyValue( this,  true, OBJECT_TO_JSVAL(obj) ) );

    success = JS_RemoveRoot(context, &obj);
    assert(success);

    return ret;
}
Пример #22
0
static JSBool
jsOnWheel( JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval )
{
   *rval = JSVAL_FALSE ;
   if( (1 == argc) && (JSTYPE_FUNCTION == JS_TypeOfValue(cx, argv[0]))){
      if( JSVAL_VOID != onWheelCode_ ){
         JS_RemoveRoot( cx, &onWheelCode_ );
      }
      onWheelCode_ = argv[0];
      JS_AddRoot( cx, &onWheelCode_ );
      *rval = JSVAL_TRUE ;
   } else
      JS_ReportError(cx,"Usage: onWheel(function);\n" );

   return JS_TRUE ;
}
Пример #23
0
void
jsd_DropValue(JSDContext* jsdc, JSDValue* jsdval)
{
    JS_ASSERT(jsdval->nref > 0);
    if(0 == --jsdval->nref)
    {
        jsd_RefreshValue(jsdc, jsdval);
        if(JSVAL_IS_GCTHING(jsdval->val))
        {
            JS_BeginRequest(jsdc->dumbContext);
            JS_RemoveRoot(jsdc->dumbContext, &jsdval->val);
            JS_EndRequest(jsdc->dumbContext);
        }
        free(jsdval);
    }
}
Пример #24
0
JSBool
js_FinishJSONParse(JSContext *cx, JSONParser *jp)
{
    if (!jp)
        return JS_TRUE;
 
    if (jp->buffer)
        js_FinishStringBuffer(jp->buffer);
    
    JS_free(cx, jp->buffer);
    if (!JS_RemoveRoot(cx, jp->objectStack))
        return JS_FALSE;
    JSBool ok = *jp->statep == JSON_PARSE_STATE_FINISHED;
    JS_free(cx, jp);
 
    return ok;
}
ScriptValuePtr TraceMonkeyEngine::createFunction(NativeFunction func, int numArgs)
{
    JSFunction* jsFunc = JS_NewFunction(context, (JSNative)func, numArgs, 0, NULL, NULL);

    bool success = JS_AddNamedRoot(context, &jsFunc, "TraceMonkeyEngine::createFunction temp val");; // Ensure our value won't be GCed
    assert(success);

    assert(jsFunc != NULL);
    assert(JSVAL_IS_OBJECT(OBJECT_TO_JSVAL(jsFunc)));

    ScriptValuePtr ret( new TraceMonkeyValue( this, true, OBJECT_TO_JSVAL(jsFunc) ) );

    success = JS_RemoveRoot(context, &jsFunc);
    assert(success);

    return ret;

}
Пример #26
0
static void
destroy_java_member_descriptor(JSContext *cx, JNIEnv *jEnv, JavaMemberDescriptor *member_descriptor)
{
    JavaMethodSpec *method, *next_method;
    if (member_descriptor->field)
        jsj_DestroyFieldSpec(cx, jEnv, member_descriptor->field);

    method = member_descriptor->methods;
    while (method) {
        next_method = method->next;
        jsj_DestroyMethodSpec(cx, jEnv, method);
        method = next_method;
    }

    JS_RemoveRoot(cx, &member_descriptor->invoke_func_obj);
    JS_FREE_IF(cx, (char *)member_descriptor->name);
    JS_free(cx, member_descriptor);
}
ScriptValuePtr TraceMonkeyValue::getProperty(std::string propertyName)
{
    assert(isValid());

    Logging::log(Logging::DEBUG, "TraceMonkeyValue::getProperty(%s): \r\n", propertyName.c_str()); printJSVAL(value);

    assert(JSVAL_IS_OBJECT(value));
    jsval ret;
    assert(JS_GetProperty(TraceMonkeyEngine::context, JSVAL_TO_OBJECT(value), propertyName.c_str(), &ret));
    bool success = JS_AddNamedRoot(TraceMonkeyEngine::context, &ret, "TraceMonkeyValue::getProperty temp val"); // Ensure our value won't be GCed
    assert(success);

    Logging::log(Logging::DEBUG, "returning: \r\n"); printJSVAL(ret);

    ScriptValuePtr retValue(new TraceMonkeyValue(engine, true, ret));

    success = JS_RemoveRoot(TraceMonkeyEngine::context, &ret); // Allow GCing, it is already marked in the retValue
    assert(success);

    return retValue;
}
Пример #28
0
NS_IMETHODIMP nsJSSh::Cleanup()
{
  nsCOMPtr<nsIXPConnect> xpc = do_GetService(nsIXPConnect::GetCID());
  if (!xpc) {
    NS_ERROR("failed to get xpconnect service");
    return NS_ERROR_FAILURE;
  }

  {
    JSAutoRequest ar(mJSContext);

    if (mContextObj != mGlobal)
      JS_RemoveRoot(mJSContext, &(mContextObj));

    JS_ClearScope(mJSContext, mGlobal);
    JS_GC(mJSContext);
  }

  JS_DestroyContext(mJSContext);
  return NS_OK;
}
ScriptValuePtr TraceMonkeyEngine::runScript(std::string script)
{
//    printf("Running script: \r\n%s\r\n", script.c_str());

    jsval ret;
    JS_EvaluateScript(context, global, script.c_str(), script.length(), "TraceMonkeyEngine", 0, &ret);
    bool success = JS_AddNamedRoot(context, &ret, "TraceMonkeyEngine::runScript temp val");; // Ensure our value won't be GCed
    assert(success);

//    printf("Script completed\r\n");

    printJSVAL(ret);

    ScriptValuePtr retValue;

    if ( !JSVAL_IS_VOID(ret) )
        retValue = ScriptValuePtr( new TraceMonkeyValue(this, true, ret) );

    success = JS_RemoveRoot(context, &ret);
    assert(success);

    return retValue;
}
Пример #30
0
static void
js_fini(void)
{
  js_plugin_t *jsp, *n;
  JSContext *cx;

  cx = js_newctx(err_reporter);
  JS_BeginRequest(cx);

  for(jsp = LIST_FIRST(&js_plugins); jsp != NULL; jsp = n) {
    n = LIST_NEXT(jsp, jsp_link);
    js_plugin_unload(cx, jsp);
  }

  JS_RemoveRoot(cx, &showtimeobj);

  JS_EndRequest(cx);
  JS_GC(cx);
  JS_DestroyContext(cx);

  JS_DestroyRuntime(runtime);
  JS_ShutDown();
}