Exemple #1
0
static int comparison_oper(VAL left, VAL right)
{
    double l, r;
    if(js_value_get_type(left) == JS_T_STRING && js_value_get_type(right) == JS_T_STRING) {
        return js_string_cmp(&js_value_get_pointer(left)->string, &js_value_get_pointer(right)->string);
    } else {
        l = js_value_get_double(js_to_number(left));
        r = js_value_get_double(js_to_number(right));
        if(l < r) {
            return -1;
        } else if(l > r) {
            return 1;
        } else {
            return 0;
        }
    }
}
Exemple #2
0
static VAL js_object_base_get(js_value_t* obj, js_string_t* prop)
{
    js_property_descriptor_t* descr = NULL;
    js_value_t* this = obj;
    while(!st_lookup(obj->object.properties, (st_data_t)prop, (st_data_t*)&descr)) {
        /* if not in object, look in prototype */
        if(js_value_is_primitive(obj->object.prototype)) {
            /* do not attempt if prototype is primitive */
            return js_value_undefined();
        }
        obj = js_value_get_pointer(obj->object.prototype);
    }
    if(!descr->is_accessor) {
        return descr->data.value;
    } else {
        if(js_value_get_type(descr->accessor.get) == JS_T_FUNCTION) {
            return js_call(descr->accessor.get, js_value_make_pointer(this), 0, NULL);
        }
        return js_value_undefined();
    }
}