⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jsobj.c

📁 Swfdec still is development software, but has also followed a rigid no-crashes-allowed policy. I b
💻 C
📖 第 1 页 / 共 5 页
字号:
                js_strncpy(&chars[nchars], JSSTRING_CHARS(gsop[j]), gsoplength);                nchars += gsoplength;                chars[nchars++] = ' ';            }            js_strncpy(&chars[nchars], idstrchars, idstrlength);            nchars += idstrlength;            if (!gsop[j])                chars[nchars++] = ':';#endif            if (vsharplength) {                js_strncpy(&chars[nchars], vsharp, vsharplength);                nchars += vsharplength;            }            js_strncpy(&chars[nchars], vchars, vlength);            nchars += vlength;            if (vsharp)                JS_free(cx, vsharp);        }    }    chars[nchars++] = '}';    if (outermost)        chars[nchars++] = ')';    chars[nchars] = 0;  error:    js_LeaveSharpObject(cx, &ida);    if (!ok) {        if (chars)            free(chars);        return ok;    }    if (!chars) {        JS_ReportOutOfMemory(cx);        return JS_FALSE;    }  make_string:    str = js_NewString(cx, chars, nchars, 0);    if (!str) {        free(chars);        return JS_FALSE;    }    *rval = STRING_TO_JSVAL(str);    return JS_TRUE;}#endif /* JS_HAS_INITIALIZERS || JS_HAS_TOSOURCE */extern int swfdec_js_is_movieclip (JSContext *cx, JSObject *obj);extern char *swfdec_movie_get_path (void *movieclip);extern void g_free (void *p);JSBooljs_obj_toString(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,                jsval *rval){    const char *name;    JSString *str;    JSClass *clasp;    clasp = OBJ_GET_CLASS(cx, obj);    if (clasp == &js_ArgumentsClass) {	*rval = STRING_TO_JSVAL(cx->runtime->emptyString);	return JS_TRUE;    }    if (swfdec_js_is_movieclip (cx, obj)) {	void *p = JS_GetPrivate (cx, obj);	if (p) {	    char *path = swfdec_movie_get_path (p);	    str = JS_NewStringCopyZ (cx, path);	    g_free (path);	    if (!str)		return JS_FALSE;	    *rval = STRING_TO_JSVAL(str);	    return JS_TRUE;	}    }    if (clasp == &js_FunctionClass) {	name = "[type Function]";    } else {	name = "[object Object]";    }    str = JS_NewStringCopyZ (cx, name);    if (!str)         return JS_FALSE;    *rval = STRING_TO_JSVAL(str);    return JS_TRUE;}static JSBoolobj_valueOf(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval){    *rval = OBJECT_TO_JSVAL(obj);    return JS_TRUE;}#if 0static JSBoolobj_eval(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval){    JSStackFrame *fp, *caller;    JSBool indirectCall;    JSObject *scopeobj;    JSString *str;    const char *file;    uintN line;    JSPrincipals *principals;    JSScript *script;    JSBool ok;#if JS_HAS_EVAL_THIS_SCOPE    JSObject *callerScopeChain = NULL, *callerVarObj = NULL;    JSBool setCallerScopeChain = JS_FALSE, setCallerVarObj = JS_FALSE;#endif    fp = cx->fp;    caller = JS_GetScriptedCaller(cx, fp);    indirectCall = (caller && caller->pc && *caller->pc != JSOP_EVAL);    if (JSVERSION_IS_ECMA(cx->version) &&        indirectCall &&        !JS_ReportErrorFlagsAndNumber(cx,                                      JSREPORT_WARNING | JSREPORT_STRICT,                                      js_GetErrorMessage, NULL,                                      JSMSG_BAD_INDIRECT_CALL,                                      js_eval_str)) {        return JS_FALSE;    }    if (!JSVAL_IS_STRING(argv[0])) {        *rval = argv[0];        return JS_TRUE;    }#if JS_HAS_SCRIPT_OBJECT    /*     * Script.prototype.compile/exec and Object.prototype.eval all take an     * optional trailing argument that overrides the scope object.     */    scopeobj = NULL;    if (argc >= 2) {        if (!js_ValueToObject(cx, argv[1], &scopeobj))            return JS_FALSE;        argv[1] = OBJECT_TO_JSVAL(scopeobj);    }    if (!scopeobj)#endif    {#if JS_HAS_EVAL_THIS_SCOPE        /* If obj.eval(str), emulate 'with (obj) eval(str)' in the caller. */        if (indirectCall) {            callerScopeChain = caller->scopeChain;            if (obj != callerScopeChain) {                scopeobj = js_NewObject(cx, &js_WithClass, obj,                                        callerScopeChain);                if (!scopeobj)                    return JS_FALSE;                /* Set fp->scopeChain too, for the compiler. */                caller->scopeChain = fp->scopeChain = scopeobj;                setCallerScopeChain = JS_TRUE;            }            callerVarObj = caller->varobj;            if (obj != callerVarObj) {                /* Set fp->varobj too, for the compiler. */                caller->varobj = fp->varobj = obj;                setCallerVarObj = JS_TRUE;            }        }        /* From here on, control must exit through label out with ok set. */#endif#if JS_BUG_EVAL_THIS_SCOPE        /* An old version used the object in which eval was found for scope. */        scopeobj = obj;#else        /* Compile using caller's current scope object. */        if (caller)            scopeobj = caller->scopeChain;#endif    }    str = JSVAL_TO_STRING(argv[0]);    if (caller) {        file = caller->script->filename;        line = js_PCToLineNumber(cx, caller->script, caller->pc);        principals = JS_EvalFramePrincipals(cx, fp, caller);    } else {        file = NULL;        line = 0;        principals = NULL;    }    /*     * Set JSFRAME_EVAL on fp and any frames (e.g., fun_call if eval.call was     * invoked) between fp and its scripted caller, to help the compiler easily     * find the same caller whose scope and var obj we've set.     *     * FIXME 244619: this nonsense should go away with a better way to pass     * params to the compiler than via the top-most frame.     */    do {        fp->flags |= JSFRAME_EVAL;    } while ((fp = fp->down) != caller);    script = JS_CompileUCScriptForPrincipals(cx, scopeobj, principals,                                             JSSTRING_CHARS(str),                                             JSSTRING_LENGTH(str),                                             file, line);    if (!script) {        ok = JS_FALSE;        goto out;    }#if !JS_BUG_EVAL_THIS_SCOPE#if JS_HAS_SCRIPT_OBJECT    if (argc < 2)#endif    {        /* Execute using caller's new scope object (might be a Call object). */        if (caller)            scopeobj = caller->scopeChain;    }#endif    ok = js_Execute(cx, scopeobj, script, caller, JSFRAME_EVAL, rval);    JS_DestroyScript(cx, script);out:#if JS_HAS_EVAL_THIS_SCOPE    /* Restore OBJ_GET_PARENT(scopeobj) not callerScopeChain in case of Call. */    if (setCallerScopeChain)        caller->scopeChain = callerScopeChain;    if (setCallerVarObj)        caller->varobj = callerVarObj;#endif    return ok;}#endifJS_STATIC_DLL_CALLBACK(const void *)resolving_GetKey(JSDHashTable *table, JSDHashEntryHdr *hdr){    JSResolvingEntry *entry = (JSResolvingEntry *)hdr;    return &entry->key;}JS_STATIC_DLL_CALLBACK(JSDHashNumber)resolving_HashKey(JSDHashTable *table, const void *ptr){    const JSResolvingKey *key = (const JSResolvingKey *)ptr;    return ((JSDHashNumber) JS_PTR_TO_UINT32(key->obj) >> JSVAL_TAGBITS) ^ key->id;}JS_PUBLIC_API(JSBool)resolving_MatchEntry(JSDHashTable *table,                     const JSDHashEntryHdr *hdr,                     const void *ptr){    const JSResolvingEntry *entry = (const JSResolvingEntry *)hdr;    const JSResolvingKey *key = (const JSResolvingKey *)ptr;    return entry->key.obj == key->obj && entry->key.id == key->id;}static const JSDHashTableOps resolving_dhash_ops = {    JS_DHashAllocTable,    JS_DHashFreeTable,    resolving_GetKey,    resolving_HashKey,    resolving_MatchEntry,    JS_DHashMoveEntryStub,    JS_DHashClearEntryStub,    JS_DHashFinalizeStub,    NULL};static JSBoolStartResolving(JSContext *cx, JSResolvingKey *key, uint32 flag,               JSResolvingEntry **entryp){    JSDHashTable *table;    JSResolvingEntry *entry;    table = cx->resolvingTable;    if (!table) {        table = JS_NewDHashTable(&resolving_dhash_ops, NULL,                                 sizeof(JSResolvingEntry),                                 JS_DHASH_MIN_SIZE);        if (!table)            goto outofmem;        cx->resolvingTable = table;    }    entry = (JSResolvingEntry *)            JS_DHashTableOperate(table, key, JS_DHASH_ADD);    if (!entry)        goto outofmem;    if (entry->flags & flag) {        /* An entry for (key, flag) exists already -- dampen recursion. */        entry = NULL;    } else {        /* Fill in key if we were the first to add entry, then set flag. */        if (!entry->key.obj)            entry->key = *key;        entry->flags |= flag;    }    *entryp = entry;    return JS_TRUE;outofmem:    JS_ReportOutOfMemory(cx);    return JS_FALSE;}static voidStopResolving(JSContext *cx, JSResolvingKey *key, uint32 flag,              JSResolvingEntry *entry, uint32 generation){    JSDHashTable *table;    /*     * Clear flag from entry->flags and return early if other flags remain.     * We must take care to re-lookup entry if the table has changed since     * it was found by StartResolving.     */    table = cx->resolvingTable;    if (table->generation != generation) {        entry = (JSResolvingEntry *)                JS_DHashTableOperate(table, key, JS_DHASH_LOOKUP);    }    entry->flags &= ~flag;    if (entry->flags)        return;    /*     * Do a raw remove only if fewer entries were removed than would cause     * alpha to be less than .5 (alpha is at most .75).  Otherwise, we just     * call JS_DHashTableOperate to re-lookup the key and remove its entry,     * compressing or shrinking the table as needed.     */    if (table->removedCount < JS_DHASH_TABLE_SIZE(table) >> 2)        JS_DHashTableRawRemove(table, &entry->hdr);    else        JS_DHashTableOperate(table, key, JS_DHASH_REMOVE);}#if JS_HAS_OBJ_WATCHPOINTstatic JSBoolobj_watch_handler(JSContext *cx, JSObject *obj, jsval id, jsval old, jsval *nvp,                  void *closure){    JSResolvingKey key;    JSResolvingEntry *entry;    uint32 generation;    JSObject *funobj;    jsval argv[3];    JSBool ok;    /* Avoid recursion on (obj, id) already being watched on cx. */    key.obj = obj;    key.id = id;    if (!StartResolving(cx, &key, JSRESFLAG_WATCH, &entry))        return JS_FALSE;    if (!entry)        return JS_TRUE;    generation = cx->resolvingTable->generation;    funobj = (JSObject *) closure;    argv[0] = id;    argv[1] = old;    argv[2] = *nvp;    ok = js_InternalCall(cx, obj, OBJECT_TO_JSVAL(funobj), 3, argv, nvp);    StopResolving(cx, &key, JSRESFLAG_WATCH, entry, generation);    return ok;}static JSBoolobj_watch(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval){    JSObject *funobj;    JSFunction *fun;    jsval userid, value;    jsid propid;    uintN attrs;    if (JSVAL_IS_FUNCTION(cx, argv[1])) {        funobj = JSVAL_TO_OBJECT(argv[1]);    } else {        fun = js_ValueToFunction(cx, &argv[1], 0);        if (!fun)            return JS_FALSE;        funobj = fun->object;    }    argv[1] = OBJECT_TO_JSVAL(funobj);    /* Compute the unique int/atom symbol id needed by js_LookupProperty. */    userid = argv[0];    if (!JS_ValueToId(cx, userid, &propid))        return JS_FALSE;    if (!OBJ_CHECK_ACCESS(cx, obj, propid, JSACC_WATCH, &value, &attrs))        return JS_FALSE;    if (attrs & JSPROP_READONLY)        return JS_TRUE;    return JS_SetWatchPoint(cx, obj, userid, obj_watch_handler, funobj);}static JSBoolobj_unwatch(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval){    return JS_ClearWatchPoint(cx, obj, argv[0], NULL, NULL);}#endif /* JS_HAS_OBJ_WATCHPOINT */#if JS_HAS_NEW_OBJ_METHODS/* * Prototype and property query methods, to complement the 'in' and * 'instanceof' operators. *//* Proposed ECMA 15.2.4.5. */static JSBoolobj_hasOwnProperty(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -