示例#1
0
void proto_number_init(Value *global)
    {
    if (!Number_prototype) bug("proto init failed?");
    int i;
    for (i = 0; i < sizeof(numpro_funcs) / sizeof(struct st_numpro_tab); ++i)
        {
        Value *n = func_utils_make_func_value(numpro_funcs[i].func);
        n->d.obj->__proto__ = Function_prototype;
        value_object_utils_insert(Number_prototype, tounichars(numpro_funcs[i].name), n, 0, 0, 0);
        }


    Value *NaN = value_new();
    value_make_number(*NaN, ieee_makenan());

    Value *Inf = value_new();
    value_make_number(*Inf, ieee_makeinf(1));

    value_object_utils_insert(global, tounichars("NaN"), NaN, 0, 0, 0);
    value_object_utils_insert(global, tounichars("Infinity"), Inf, 0, 0, 0);
    }
示例#2
0
/* charCodeAt */
static int strpto_charCodeAt(PSTATE *ps, Value *args, Value *_this, Value *ret, int asc)
{
	if (asc) die("Execute String.prototype.charCodeAt as constructor\n");

	Value target = { 0 };
	value_copy(target, *_this);
	value_tostring(&target);
	
	int slen = unistrlen(target.d.str);
	int pos = 0;
	Value *vpos;
	if ((vpos = value_object_lookup_array(args, 0, NULL))) {
		value_toint32(vpos);
		pos = (int)vpos->d.num;
	}

	if (pos < 0 || pos >= slen) {
		value_make_number(*ret, ieee_makenan());
	} else {
		value_make_number(*ret, target.d.str[pos]);
	}
	value_erase(target);
	return 0;
}