Exemplo n.º 1
0
FlmRecord * CSPStore::FindObject(FLMUNICODE *pId)
{
	RCODE			rc = FERR_OK;
	HFCURSOR		cursor = 0;
	FlmRecord	*pRec = NULL;
	FlmRecord	*pRWRec = NULL;
	FLMUINT		fieldId;
	FLMUINT		count;

	rc = NameToId(CS_Name_GUID, &fieldId);
	if (RC_OK(rc))
	{
		rc = FlmCursorInit(m_hFlaim, FLM_DATA_CONTAINER, &cursor);
		if (RC_OK(rc))
		{
			rc = FlmCursorAddField(cursor, fieldId, 0);
			if (RC_OK(rc))
			{
				rc = FlmCursorAddOp(cursor, FLM_EQ_OP, 0);
				if (RC_OK(rc))
				{
					rc = FlmCursorAddValue(cursor, FLM_UNICODE_VAL, pId, 0);
					if (RC_OK(rc))
					{
						rc = FlmCursorRecCount(cursor, &count);
						if (RC_OK(rc) && count != 0)
						{
							rc = FlmCursorNext(cursor, &pRec);
							if (RC_OK(rc))
							{
								pRWRec = pRec->copy();
								pRec->Release();
								pRec = NULL;
							}
						}
					}
				}
			}
			FlmCursorFree(&cursor);
		}
	}
	return (pRWRec);
} // CSPStore::FindObject()
Exemplo n.º 2
0
static bool
ProtoGetterImpl(JSContext *cx, CallArgs args)
{
    JS_ASSERT(TestProtoGetterThis(args.thisv()));

    const Value &thisv = args.thisv();
    if (thisv.isPrimitive() && !BoxNonStrictThis(cx, args))
        return false;

    unsigned dummy;
    Rooted<JSObject*> obj(cx, &args.thisv().toObject());
    Rooted<jsid> nid(cx, NameToId(cx->runtime->atomState.protoAtom));
    Rooted<Value> v(cx);
    if (!CheckAccess(cx, obj, nid, JSACC_PROTO, v.address(), &dummy))
        return false;

    args.rval().set(v);
    return true;
}
Exemplo n.º 3
0
long wxTreeLayoutStored::AddChild(const wxString& name, const wxString& parent)
{
    if (m_num < (m_maxNodes -1 ))
    {
        long i = -1;
        if (parent != wxT(""))
            i = NameToId(parent);
        else m_parentNode = m_num;

        m_nodes[m_num].m_parentId = i;
        m_nodes[m_num].m_name = name;
        m_nodes[m_num].m_x = m_nodes[m_num].m_y = 0;
        m_nodes[m_num].m_clientData = 0;
        m_num ++;

        return (m_num - 1);
    }
    else
        return -1;
}
Exemplo n.º 4
0
JSObject *
GlobalObject::initFunctionAndObjectClasses(JSContext *cx)
{
    Rooted<GlobalObject*> self(cx, this);

    JS_THREADSAFE_ASSERT(cx->compartment != cx->runtime->atomsCompartment);
    JS_ASSERT(isNative());

    /*
     * Calling a function from a cleared global triggers this (yeah, I know).
     * Uncomment this once bug 470510 is fixed (if that bug doesn't remove
     * isCleared entirely).
     */
    // JS_ASSERT(!isCleared());

    /* If cx has no global object, make this the global object. */
    if (!cx->globalObject)
        JS_SetGlobalObject(cx, self);

    RootedObject objectProto(cx);

    /*
     * Create |Object.prototype| first, mirroring CreateBlankProto but for the
     * prototype of the created object.
     */
    objectProto = NewObjectWithGivenProto(cx, &ObjectClass, NULL, self);
    if (!objectProto || !objectProto->setSingletonType(cx))
        return NULL;

    /*
     * The default 'new' type of Object.prototype is required by type inference
     * to have unknown properties, to simplify handling of e.g. heterogenous
     * objects in JSON and script literals.
     */
    if (!objectProto->setNewTypeUnknown(cx))
        return NULL;

    /* Create |Function.prototype| next so we can create other functions. */
    RootedFunction functionProto(cx);
    {
        JSObject *functionProto_ = NewObjectWithGivenProto(cx, &FunctionClass, objectProto, self);
        if (!functionProto_)
            return NULL;
        functionProto = functionProto_->toFunction();

        /*
         * Bizarrely, |Function.prototype| must be an interpreted function, so
         * give it the guts to be one.
         */
        JSObject *proto = js_NewFunction(cx, functionProto,
                                         NULL, 0, JSFUN_INTERPRETED, self, NULL);
        if (!proto)
            return NULL;
        JS_ASSERT(proto == functionProto);
        functionProto->flags |= JSFUN_PROTOTYPE;

        const char *rawSource = "() {\n}";
        size_t sourceLen = strlen(rawSource);
        jschar *source = InflateString(cx, rawSource, &sourceLen);
        if (!source)
            return NULL;
        ScriptSource *ss = cx->new_<ScriptSource>();
        if (!ss) {
            cx->free_(source);
            return NULL;
        }
        ScriptSourceHolder ssh(cx->runtime, ss);
        ss->setSource(source, sourceLen);

        CompileOptions options(cx);
        options.setNoScriptRval(true)
               .setVersion(JSVERSION_DEFAULT);
        Rooted<JSScript*> script(cx, JSScript::Create(cx,
                                                      /* enclosingScope = */ NullPtr(),
                                                      /* savedCallerFun = */ false,
                                                      options,
                                                      /* staticLevel = */ 0,
                                                      ss,
                                                      0,
                                                      ss->length()));
        if (!script || !JSScript::fullyInitTrivial(cx, script))
            return NULL;

        functionProto->initScript(script);
        functionProto->getType(cx)->interpretedFunction = functionProto;
        script->setFunction(functionProto);

        if (!functionProto->setSingletonType(cx))
            return NULL;

        /*
         * The default 'new' type of Function.prototype is required by type
         * inference to have unknown properties, to simplify handling of e.g.
         * CloneFunctionObject.
         */
        if (!functionProto->setNewTypeUnknown(cx))
            return NULL;
    }

    /* Create the Object function now that we have a [[Prototype]] for it. */
    RootedFunction objectCtor(cx);
    {
        JSObject *ctor = NewObjectWithGivenProto(cx, &FunctionClass, functionProto, self);
        if (!ctor)
            return NULL;
        objectCtor = js_NewFunction(cx, ctor, js_Object, 1, JSFUN_CONSTRUCTOR, self,
                                    CLASS_NAME(cx, Object));
        if (!objectCtor)
            return NULL;
    }

    /*
     * Install |Object| and |Object.prototype| for the benefit of subsequent
     * code that looks for them.
     */
    self->setObjectClassDetails(objectCtor, objectProto);

    /* Create |Function| so it and |Function.prototype| can be installed. */
    RootedFunction functionCtor(cx);
    {
        // Note that ctor is rooted purely for the JS_ASSERT at the end
        RootedObject ctor(cx, NewObjectWithGivenProto(cx, &FunctionClass, functionProto, self));
        if (!ctor)
            return NULL;
        functionCtor = js_NewFunction(cx, ctor, Function, 1, JSFUN_CONSTRUCTOR, self,
                                      CLASS_NAME(cx, Function));
        if (!functionCtor)
            return NULL;
        JS_ASSERT(ctor == functionCtor);
    }

    /*
     * Install |Function| and |Function.prototype| so that we can freely create
     * functions and objects without special effort.
     */
    self->setFunctionClassDetails(functionCtor, functionProto);

    /*
     * The hard part's done: now go back and add all the properties these
     * primordial values have.
     */
    if (!LinkConstructorAndPrototype(cx, objectCtor, objectProto) ||
        !DefinePropertiesAndBrand(cx, objectProto, NULL, object_methods))
    {
        return NULL;
    }

    /*
     * Add an Object.prototype.__proto__ accessor property to implement that
     * extension (if it's actually enabled).  Cache the getter for this
     * function so that cross-compartment [[Prototype]]-getting is implemented
     * in one place.
     */
    Rooted<JSFunction*> getter(cx, js_NewFunction(cx, NULL, ProtoGetter, 0, 0, self, NULL));
    if (!getter)
        return NULL;
#if JS_HAS_OBJ_PROTO_PROP
    Rooted<JSFunction*> setter(cx, js_NewFunction(cx, NULL, ProtoSetter, 0, 0, self, NULL));
    if (!setter)
        return NULL;
    RootedValue undefinedValue(cx, UndefinedValue());
    if (!objectProto->defineProperty(cx, cx->runtime->atomState.protoAtom, undefinedValue,
                                     JS_DATA_TO_FUNC_PTR(PropertyOp, getter.get()),
                                     JS_DATA_TO_FUNC_PTR(StrictPropertyOp, setter.get()),
                                     JSPROP_GETTER | JSPROP_SETTER | JSPROP_SHARED))
    {
        return NULL;
    }
#endif /* JS_HAS_OBJ_PROTO_PROP */
    self->setProtoGetter(getter);


    if (!DefinePropertiesAndBrand(cx, objectCtor, NULL, object_static_methods) ||
        !LinkConstructorAndPrototype(cx, functionCtor, functionProto) ||
        !DefinePropertiesAndBrand(cx, functionProto, NULL, function_methods) ||
        !DefinePropertiesAndBrand(cx, functionCtor, NULL, NULL))
    {
        return NULL;
    }

    /* Add the global Function and Object properties now. */
    jsid objectId = NameToId(CLASS_NAME(cx, Object));
    if (!self->addDataProperty(cx, objectId, JSProto_Object + JSProto_LIMIT * 2, 0))
        return NULL;
    jsid functionId = NameToId(CLASS_NAME(cx, Function));
    if (!self->addDataProperty(cx, functionId, JSProto_Function + JSProto_LIMIT * 2, 0))
        return NULL;

    /* Heavy lifting done, but lingering tasks remain. */

    /* ES5 15.1.2.1. */
    RootedId id(cx, NameToId(cx->runtime->atomState.evalAtom));
    JSObject *evalobj = js_DefineFunction(cx, self, id, IndirectEval, 1, JSFUN_STUB_GSOPS);
    if (!evalobj)
        return NULL;
    self->setOriginalEval(evalobj);

    /* ES5 13.2.3: Construct the unique [[ThrowTypeError]] function object. */
    RootedFunction throwTypeError(cx, js_NewFunction(cx, NULL, ThrowTypeError, 0, 0, self, NULL));
    if (!throwTypeError)
        return NULL;
    if (!throwTypeError->preventExtensions(cx))
        return NULL;
    self->setThrowTypeError(throwTypeError);

    RootedObject intrinsicsHolder(cx, JS_NewObject(cx, NULL, NULL, self));
    if (!intrinsicsHolder)
        return NULL;
    self->setIntrinsicsHolder(intrinsicsHolder);
    if (!JS_DefineFunctions(cx, intrinsicsHolder, intrinsic_functions))
        return NULL;

    /*
     * The global object should have |Object.prototype| as its [[Prototype]].
     * Eventually we'd like to have standard classes be there from the start,
     * and thus we would know we were always setting what had previously been a
     * null [[Prototype]], but right now some code assumes it can set the
     * [[Prototype]] before standard classes have been initialized.  For now,
     * only set the [[Prototype]] if it hasn't already been set.
     */
    if (self->shouldSplicePrototype(cx) && !self->splicePrototype(cx, objectProto))
        return NULL;

    /*
     * Notify any debuggers about the creation of the script for
     * |Function.prototype| -- after all initialization, for simplicity.
     */
    js_CallNewScriptHook(cx, functionProto->script(), functionProto);
    return functionProto;
}
Exemplo n.º 5
0
RCODE CSPStore::GetObject(FLMUNICODE *pProperty, FLMUNICODE *pValue, int* pnChars, FLMUNICODE *pBuffer)
{
	RCODE			rc = FERR_OK;
	HFCURSOR		cursor = 0;
	FlmRecord		*pRec = NULL;
	FLMUINT			fieldId;
	FLMUINT			count;
	CSPStoreObject *pObject = NULL;
	int				buffSize = *pnChars;
	int				nChars = *pnChars;
	int				len = 0;

	*pnChars = 0;
	rc = NameToId(pProperty, &fieldId);
	if (RC_OK(rc))
	{
		rc = FlmCursorInit(m_hFlaim, FLM_DATA_CONTAINER, &cursor);
		if (RC_OK(rc))
		{
			rc = FlmCursorAddField(cursor, fieldId, 0);
			if (RC_OK(rc))
			{
				rc = FlmCursorAddOp(cursor, FLM_EQ_OP,	0);
				if (RC_OK(rc))
				{
					rc = FlmCursorAddValue(cursor, FLM_UNICODE_VAL,	pValue, 0);
					if (RC_OK(rc))
					{
						rc = FlmCursorRecCount(cursor, &count);
						if (RC_OK(rc) && count != 0)
						{
							rc = FlmCursorNext(cursor,	&pRec);
						}
						else
						{
							// Not found
							rc = FERR_NOT_FOUND;
						}
					}
				}
			}
			FlmCursorFree(&cursor);
		}
	}

	if (RC_OK(rc))
	{
		pObject = new CSPStoreObject(this, pRec);
		if (pObject != NULL)
		{
			if (pObject->GetXmlSize() < buffSize)
			{
				int			endTagLen = f_unilen((FLMUNICODE*)XmlObjectListEndString);
				FLMUNICODE *pBuff = pBuffer;
			
				if ((len = flmstrcpy(pBuff, (FLMUNICODE*)XmlObectListString, nChars)) != -1)
				{
					nChars -= len + endTagLen;
					pBuff += len;
					if ((len = pObject->ToXML(pBuff, nChars, true, false)) != -1)
					{
						nChars -= len;
						pBuff += len;					
						if ((len = flmstrcpy(pBuff, (FLMUNICODE*)XmlObjectListEndString, nChars + endTagLen)) != -1)
						{
							nChars++;
							*pnChars = buffSize - nChars + 1;
						}
					}
				}
			}
			else
			{
				*pnChars = pObject->GetXmlSize() + 1;
				rc = FERR_MEM;
			}
			delete pObject;
		}
	}
	return (rc);
}
Exemplo n.º 6
0
RCODE CSPStore::MQSearch(FLMUNICODE *pCollectionId, FLMUNICODE *pProperty, FLMINT op, FLMUNICODE *pValue, FLMUNICODE *pType,FLMUNICODE *pProperty1, FLMINT op1, FLMUNICODE *pValue1, FLMUNICODE *pType1, FLMUNICODE *pProperty2, FLMINT op2, FLMUNICODE *pValue2, FLMUNICODE *pType2, FLMUNICODE *pProperty3, FLMINT op3, FLMUNICODE *pValue3, FLMUNICODE *pType3, FLMUINT qryCount, FLMBOOL caseSensitive, FLMUINT *pCount, CSPObjectIterator **ppIterator)
{
	RCODE				rc = FERR_OK;
	HFCURSOR			cursor = 0;
	FLMUINT				fieldId;
	FLMUINT				sec_fieldId;
	CSPObjectIterator	*pIterator = 0;
	CSPValue			*pCspValue;
	CSPValue			*sec_pCspValue;
	FLMBOOL				includeColId = true;


	pCspValue = CSPStoreObject::CreateProperty(pValue, pProperty, CSPStore::StringToType(pType));

	if (pCspValue)
	{
		rc = NameToId(pProperty, &fieldId);
		if (RC_OK(rc))
		{
			rc = FlmCursorInit(m_hFlaim, FLM_DATA_CONTAINER, &cursor);
			if (RC_OK(rc))
			{
				FLMUINT indexId;
				// Setup the index to use
				if (RC_OK(m_pDB->GetIndexId(pProperty, fieldId, &indexId)))
				{
					FlmCursorConfig(cursor, FCURSOR_SET_FLM_IX, (void *)indexId, NULL);
				}

				if (caseSensitive)
				{
					rc = FlmCursorSetMode(cursor, FLM_WILD);
				}
				rc = FlmCursorAddField(cursor, fieldId, 0);
				if (RC_OK(rc))
				{
					rc = FlmCursorAddOp(cursor, (QTYPES)op,	0);
					if (RC_OK(rc))
					{
						rc = FlmCursorAddValue(cursor, pCspValue->GetSearchType(),	pCspValue->SearchVal(), pCspValue->SearchSize());
						if (pCollectionId && RC_OK(rc))
						{
							includeColId = false;
							rc = FlmCursorAddOp(cursor, FLM_AND_OP, 0);
							if (RC_OK(rc))
							{
								rc = FlmCursorAddField(cursor, CS_Id_CollectionId, 0);
								if (RC_OK(rc))
								{
									rc = FlmCursorAddOp(cursor, FLM_EQ_OP,	0);
									if (RC_OK(rc))
									{
										rc = FlmCursorAddValue(cursor, FLM_UNICODE_VAL,	pCollectionId, 0);
									}
								}
							}
						}
					}
				}
				if(qryCount >= 2)
				{
					sec_pCspValue = CSPStoreObject::CreateProperty(pValue1, pProperty1, CSPStore::StringToType(pType1));
					rc=NameToId(pProperty1, &sec_fieldId);
					if(RC_OK(rc))
					{
						rc = FlmCursorAddOp(cursor, FLM_AND_OP, 0);
						if(RC_OK(rc))
						{
							rc = FlmCursorAddField(cursor, sec_fieldId, 0);
							if(RC_OK(rc))
							{
								rc = FlmCursorAddOp(cursor, (QTYPES)op1, 0);
								if(RC_OK(rc))
								{
									rc = FlmCursorAddValue(cursor, sec_pCspValue->GetSearchType(),      sec_pCspValue->SearchVal(), sec_pCspValue->SearchSize());
								}
							}
						}
						
					}
				}
				if(qryCount >= 3)
				{
					sec_pCspValue = CSPStoreObject::CreateProperty(pValue2, pProperty2, CSPStore::StringToType(pType2));
					rc=NameToId(pProperty2, &sec_fieldId);
					if(RC_OK(rc))
					{
						rc = FlmCursorAddOp(cursor, FLM_AND_OP, 0);
						if(RC_OK(rc))
						{
							rc = FlmCursorAddField(cursor, sec_fieldId, 0);
							if(RC_OK(rc))
							{
								rc = FlmCursorAddOp(cursor, (QTYPES)op2, 0);
								if(RC_OK(rc))
								{
									rc = FlmCursorAddValue(cursor, sec_pCspValue->GetSearchType(),      sec_pCspValue->SearchVal(), sec_pCspValue->SearchSize());
								}
							}
						}
						
					}
				}
				if(qryCount >= 4)
				{
					sec_pCspValue = CSPStoreObject::CreateProperty(pValue3, pProperty3, CSPStore::StringToType(pType3));
					rc=NameToId(pProperty3, &sec_fieldId);
					if(RC_OK(rc))
					{
						rc = FlmCursorAddOp(cursor, FLM_AND_OP, 0);
						if(RC_OK(rc))
						{
							rc = FlmCursorAddField(cursor, sec_fieldId, 0);
							if(RC_OK(rc))
							{
								rc = FlmCursorAddOp(cursor, (QTYPES)op3, 0);
								if(RC_OK(rc))
								{
									rc = FlmCursorAddValue(cursor, sec_pCspValue->GetSearchType(),      sec_pCspValue->SearchVal(), sec_pCspValue->SearchSize());
								}
							}
						}
						
					}
				}
				if (RC_OK(rc))
				{
					rc = FlmCursorRecCount(cursor, pCount);
					pIterator = new CSPObjectIterator(cursor, *pCount, includeColId);
				}
				FlmCursorFree(&cursor);
			}
		}
		else
		{
			// No properties exist with the specified name.
			rc = FERR_OK;
			*pCount = 0;
			pIterator = new CSPObjectIterator(NULL, *pCount, includeColId);
		}
		delete pCspValue;
	}

	*ppIterator = pIterator;
	return (rc);

} // CSPStore::MQSearch()
Exemplo n.º 7
0
unsigned char CSDLKeyboard::Event2ASCII(const SInputEvent& event)
{

	SDL_Keycode keySym = (SDL_Keycode)NameToId(event.keyName);
	char ascii = 0;
	bool alpha = false;
    
	switch (keySym)
	{
        case SDLK_BACKSPACE: ascii = '\b'; break;
        case SDLK_TAB: ascii = '\t'; break;
        case SDLK_RETURN: ascii = '\r'; break;
        case SDLK_ESCAPE: ascii = '\x1b'; break;
        case SDLK_SPACE: ascii = ' '; break;
        case SDLK_EXCLAIM: ascii = '!'; break;
        case SDLK_QUOTEDBL: ascii = '"'; break;
        case SDLK_HASH: ascii = '#'; break;
        case SDLK_DOLLAR: ascii = '$'; break;
        case SDLK_AMPERSAND: ascii = '&'; break;
        case SDLK_QUOTE: ascii = '\''; break;
        case SDLK_LEFTPAREN: ascii = '('; break;
        case SDLK_RIGHTPAREN: ascii = ')'; break;
        case SDLK_ASTERISK: ascii = '*'; break;
        case SDLK_PLUS: ascii = '+'; break;
        case SDLK_COMMA: ascii = ','; break;
        case SDLK_MINUS: ascii = '-'; break;
        case SDLK_PERIOD: ascii = '.'; break;
        case SDLK_SLASH: ascii = '/'; break;
        case SDLK_0: ascii = '0'; break;
        case SDLK_1: ascii = '1'; break;
        case SDLK_2: ascii = '2'; break;
        case SDLK_3: ascii = '3'; break;
        case SDLK_4: ascii = '4'; break;
        case SDLK_5: ascii = '5'; break;
        case SDLK_6: ascii = '6'; break;
        case SDLK_7: ascii = '7'; break;
        case SDLK_8: ascii = '8'; break;
        case SDLK_9: ascii = '9'; break;
        case SDLK_COLON: ascii = ':'; break;
        case SDLK_SEMICOLON: ascii = ';'; break;
        case SDLK_LESS: ascii = '<'; break;
        case SDLK_EQUALS: ascii = '='; break;
        case SDLK_GREATER: ascii = '>'; break;
        case SDLK_QUESTION: ascii = '?'; break;
        case SDLK_AT: ascii = '@'; break;
        case SDLK_LEFTBRACKET: ascii = '['; break;
        case SDLK_BACKSLASH: ascii = '\\'; break;
        case SDLK_RIGHTBRACKET: ascii = ']'; break;
        case SDLK_CARET: ascii = '^'; break;
        case SDLK_UNDERSCORE: ascii = '_'; break;
        case SDLK_BACKQUOTE: ascii = '`'; break;
        case SDLK_a: ascii = 'a'; alpha = true; break;
        case SDLK_b: ascii = 'b'; alpha = true; break;
        case SDLK_c: ascii = 'c'; alpha = true; break;
        case SDLK_d: ascii = 'd'; alpha = true; break;
        case SDLK_e: ascii = 'e'; alpha = true; break;
        case SDLK_f: ascii = 'f'; alpha = true; break;
        case SDLK_g: ascii = 'g'; alpha = true; break;
        case SDLK_h: ascii = 'h'; alpha = true; break;
        case SDLK_i: ascii = 'i'; alpha = true; break;
        case SDLK_j: ascii = 'j'; alpha = true; break;
        case SDLK_k: ascii = 'k'; alpha = true; break;
        case SDLK_l: ascii = 'l'; alpha = true; break;
        case SDLK_m: ascii = 'm'; alpha = true; break;
        case SDLK_n: ascii = 'n'; alpha = true; break;
        case SDLK_o: ascii = 'o'; alpha = true; break;
        case SDLK_p: ascii = 'p'; alpha = true; break;
        case SDLK_q: ascii = 'q'; alpha = true; break;
        case SDLK_r: ascii = 'r'; alpha = true; break;
        case SDLK_s: ascii = 's'; alpha = true; break;
        case SDLK_t: ascii = 't'; alpha = true; break;
        case SDLK_u: ascii = 'u'; alpha = true; break;
        case SDLK_v: ascii = 'v'; alpha = true; break;
        case SDLK_w: ascii = 'w'; alpha = true; break;
        case SDLK_x: ascii = 'x'; alpha = true; break;
        case SDLK_y: ascii = 'y'; alpha = true; break;
        case SDLK_z: ascii = 'z'; alpha = true; break;
        case SDLK_DELETE: ascii = '\x7f'; break;
        case SDLK_KP_0: ascii = '0'; break;
        case SDLK_KP_1: ascii = '1'; break;
        case SDLK_KP_2: ascii = '2'; break;
        case SDLK_KP_3: ascii = '3'; break;
        case SDLK_KP_4: ascii = '4'; break;
        case SDLK_KP_5: ascii = '5'; break;
        case SDLK_KP_6: ascii = '6'; break;
        case SDLK_KP_7: ascii = '7'; break;
        case SDLK_KP_8: ascii = '8'; break;
        case SDLK_KP_9: ascii = '9'; break;
        case SDLK_KP_PERIOD: ascii = '.'; break;
        case SDLK_KP_DIVIDE: ascii = '/'; break;
        case SDLK_KP_MULTIPLY: ascii = '*'; break;
        case SDLK_KP_MINUS: ascii = '-'; break;
        case SDLK_KP_PLUS: ascii = '+'; break;
        case SDLK_KP_ENTER: ascii = '\r'; break;
        case SDLK_KP_EQUALS: ascii = '='; break;
        default: ascii = 0; break;
	}
	if (ascii && (event.modifiers & (eMM_LShift | eMM_RShift | eMM_CapsLock)))
		ascii = toupper(ascii);
	return ascii;
}
Exemplo n.º 8
0
JSObject *
GlobalObject::initFunctionAndObjectClasses(JSContext *cx)
{
    Rooted<GlobalObject*> self(cx, this);

    JS_THREADSAFE_ASSERT(cx->compartment != cx->runtime->atomsCompartment);
    JS_ASSERT(isNative());

    /*
     * Calling a function from a cleared global triggers this (yeah, I know).
     * Uncomment this once bug 470510 is fixed (if that bug doesn't remove
     * isCleared entirely).
     */
    // JS_ASSERT(!isCleared());

    /* If cx has no global object, make this the global object. */
    if (!cx->globalObject)
        JS_SetGlobalObject(cx, self);

    RootedObject objectProto(cx);

    /*
     * Create |Object.prototype| first, mirroring CreateBlankProto but for the
     * prototype of the created object.
     */
    objectProto = NewObjectWithGivenProto(cx, &ObjectClass, NULL, self);
    if (!objectProto || !objectProto->setSingletonType(cx))
        return NULL;

    /*
     * The default 'new' type of Object.prototype is required by type inference
     * to have unknown properties, to simplify handling of e.g. heterogenous
     * objects in JSON and script literals.
     */
    if (!objectProto->setNewTypeUnknown(cx))
        return NULL;

    /* Create |Function.prototype| next so we can create other functions. */
    RootedFunction functionProto(cx);
    {
        JSObject *functionProto_ = NewObjectWithGivenProto(cx, &FunctionClass, objectProto, self);
        if (!functionProto_)
            return NULL;
        functionProto = functionProto_->toFunction();

        /*
         * Bizarrely, |Function.prototype| must be an interpreted function, so
         * give it the guts to be one.
         */
        JSObject *proto = js_NewFunction(cx, functionProto,
                                         NULL, 0, JSFUN_INTERPRETED, self, NULL);
        if (!proto)
            return NULL;
        JS_ASSERT(proto == functionProto);
        functionProto->flags |= JSFUN_PROTOTYPE;

        JSScript *script =
            JSScript::NewScript(cx, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, JSVERSION_DEFAULT);
        if (!script)
            return NULL;
        script->noScriptRval = true;
        script->code[0] = JSOP_STOP;
        script->code[1] = SRC_NULL;
        functionProto->initScript(script);
        functionProto->getType(cx)->interpretedFunction = functionProto;
        script->setFunction(functionProto);

        if (!functionProto->setSingletonType(cx))
            return NULL;

        /*
         * The default 'new' type of Function.prototype is required by type
         * inference to have unknown properties, to simplify handling of e.g.
         * CloneFunctionObject.
         */
        if (!functionProto->setNewTypeUnknown(cx))
            return NULL;
    }

    /* Create the Object function now that we have a [[Prototype]] for it. */
    RootedFunction objectCtor(cx);
    {
        JSObject *ctor = NewObjectWithGivenProto(cx, &FunctionClass, functionProto, self);
        if (!ctor)
            return NULL;
        objectCtor = js_NewFunction(cx, ctor, js_Object, 1, JSFUN_CONSTRUCTOR, self,
                                    CLASS_NAME(cx, Object));
        if (!objectCtor)
            return NULL;
    }

    /*
     * Install |Object| and |Object.prototype| for the benefit of subsequent
     * code that looks for them.
     */
    self->setObjectClassDetails(objectCtor, objectProto);

    /* Create |Function| so it and |Function.prototype| can be installed. */
    RootedFunction functionCtor(cx);
    {
        JSObject *ctor =
            NewObjectWithGivenProto(cx, &FunctionClass, functionProto, self);
        if (!ctor)
            return NULL;
        functionCtor = js_NewFunction(cx, ctor, Function, 1, JSFUN_CONSTRUCTOR, self,
                                      CLASS_NAME(cx, Function));
        if (!functionCtor)
            return NULL;
        JS_ASSERT(ctor == functionCtor);
    }

    /*
     * Install |Function| and |Function.prototype| so that we can freely create
     * functions and objects without special effort.
     */
    self->setFunctionClassDetails(functionCtor, functionProto);

    /*
     * The hard part's done: now go back and add all the properties these
     * primordial values have.
     */
    if (!LinkConstructorAndPrototype(cx, objectCtor, objectProto) ||
            !DefinePropertiesAndBrand(cx, objectProto, object_props, object_methods) ||
            !DefinePropertiesAndBrand(cx, objectCtor, NULL, object_static_methods) ||
            !LinkConstructorAndPrototype(cx, functionCtor, functionProto) ||
            !DefinePropertiesAndBrand(cx, functionProto, NULL, function_methods) ||
            !DefinePropertiesAndBrand(cx, functionCtor, NULL, NULL))
    {
        return NULL;
    }

    /* Add the global Function and Object properties now. */
    jsid objectId = NameToId(CLASS_NAME(cx, Object));
    if (!self->addDataProperty(cx, objectId, JSProto_Object + JSProto_LIMIT * 2, 0))
        return NULL;
    jsid functionId = NameToId(CLASS_NAME(cx, Function));
    if (!self->addDataProperty(cx, functionId, JSProto_Function + JSProto_LIMIT * 2, 0))
        return NULL;

    /* Heavy lifting done, but lingering tasks remain. */

    /* ES5 15.1.2.1. */
    RootedId id(cx, NameToId(cx->runtime->atomState.evalAtom));
    JSObject *evalobj = js_DefineFunction(cx, self, id, eval, 1, JSFUN_STUB_GSOPS);
    if (!evalobj)
        return NULL;
    self->setOriginalEval(evalobj);

    /* ES5 13.2.3: Construct the unique [[ThrowTypeError]] function object. */
    RootedFunction throwTypeError(cx);
    throwTypeError = js_NewFunction(cx, NULL, ThrowTypeError, 0, 0, self, NULL);
    if (!throwTypeError)
        return NULL;
    if (!throwTypeError->preventExtensions(cx))
        return NULL;
    self->setThrowTypeError(throwTypeError);

    /*
     * The global object should have |Object.prototype| as its [[Prototype]].
     * Eventually we'd like to have standard classes be there from the start,
     * and thus we would know we were always setting what had previously been a
     * null [[Prototype]], but right now some code assumes it can set the
     * [[Prototype]] before standard classes have been initialized.  For now,
     * only set the [[Prototype]] if it hasn't already been set.
     */
    if (self->shouldSplicePrototype(cx) && !self->splicePrototype(cx, objectProto))
        return NULL;

    /*
     * Notify any debuggers about the creation of the script for
     * |Function.prototype| -- after all initialization, for simplicity.
     */
    js_CallNewScriptHook(cx, functionProto->script(), functionProto);
    return functionProto;
}