Пример #1
0
 llvm::LoadInst*
 LoadInst_GetLLVMObj(ejsval val)
 {
     if (EJSVAL_IS_NULL(val)) return NULL;
     return ((LoadInst*)EJSVAL_TO_OBJECT(val))->llvm_load;
 }
Пример #2
0
// ES6: 23.2.1.1 Set ( [ iterable ] )
static ejsval
_ejs_Set_impl (ejsval env, ejsval _this, uint32_t argc, ejsval *args)
{
    // 1. Let set be the this value. 
    ejsval set = _this;

    if (EJSVAL_IS_UNDEFINED(set)) {
        EJSObject* obj = (EJSObject*)_ejs_gc_new(EJSSet);
        _ejs_init_object (obj, _ejs_Set_prototype, &_ejs_Set_specops);
        set = OBJECT_TO_EJSVAL(obj);
    }

    // 2. If Type(set) is not Object then, throw a TypeError exception. 
    if (!EJSVAL_IS_OBJECT(set))
        _ejs_throw_nativeerror_utf8 (EJS_TYPE_ERROR, "Set constructor called with non-object this.");

    // 3. If set does not have a [[SetData]] internal slot, then throw a TypeError exception. 
    if (!EJSVAL_IS_SET(set))
        _ejs_throw_nativeerror_utf8 (EJS_TYPE_ERROR, "Set constructor called with non-Set this.");

    EJSSet* _set = EJSVAL_TO_SET(set);

    // 4. If set’s [[SetData]] internal slot is not undefined, then throw a TypeError exception.
    if (_set->head_insert)
        _ejs_throw_nativeerror_utf8 (EJS_TYPE_ERROR, "Set constructor called with an already initialized Set");

    // 5. If iterable is not present, let iterable be undefined. 
    ejsval iterable = _ejs_undefined;
    if (argc > 0)
        iterable = args[0];
    ejsval iter = _ejs_undefined;
    ejsval adder = _ejs_undefined;

    // 6. If iterable is either undefined or null, then let iter be undefined.
    // 7. Else, 
    if (!EJSVAL_IS_UNDEFINED(iterable) && !EJSVAL_IS_NULL(iterable)) {
        //    a. Let iter be the result of GetIterator(iterable). 
        //    b. ReturnIfAbrupt(iter). 
        iter = GetIterator (iterable, _ejs_undefined);
        //    c. Let adder be the result of Get(set, "add").
        //    d. ReturnIfAbrupt(adder). 
        adder = Get (set, _ejs_atom_add);
        //    e. If IsCallable(adder) is false, throw a TypeError Exception.
        if (!EJSVAL_IS_CALLABLE(adder))
            _ejs_throw_nativeerror_utf8 (EJS_TYPE_ERROR, "Set.prototype.add is not a function");
    }
    // 8. If the value of sets’s [[SetData]] internal slot is not undefined, then throw a TypeError exception. 
    // 9. Assert: set has not been reentrantly initialized. 
    // 10. Set set’s [[SetData]] internal slot to a new empty List.

    // 11. If iter is undefined, then return set. 
    if (EJSVAL_IS_UNDEFINED(iter))
        return set;

    // 12. Repeat 
    for (;;) {
        //    a. Let next be the result of IteratorStep(iter).
        //    b. ReturnIfAbrupt(next).
        ejsval next = IteratorStep (iter);

        //    c. If next is false, then return set.
        if (!EJSVAL_TO_BOOLEAN(next))
            return set;

        //    d. Let nextValue be IteratorValue(next).
        //    e. ReturnIfAbrupt(nextValue).
        ejsval nextValue = IteratorValue (next);

        //    f. Let status be the result of calling the [[Call]] internal method of adder with set as thisArgument
        //       and a List whose sole element is nextValue as argumentsList.
        //    g. ReturnIfAbrupt(status).
        _ejs_invoke_closure (adder, set, 1, &nextValue);
    }

    return set;
}
Пример #3
0
 llvm::Function*
 Function_GetLLVMObj(ejsval val)
 {
     if (EJSVAL_IS_NULL(val)) return NULL;
     return ((Function*)EJSVAL_TO_OBJECT(val))->llvm_fun;
 }
Пример #4
0
 llvm::Module*
 Module_GetLLVMObj(ejsval val)
 {
     if (EJSVAL_IS_NULL(val)) return NULL;
     return ((Module*)EJSVAL_TO_OBJECT(val))->llvm_module;
 }
Пример #5
0
 llvm::StructType*
 StructType_GetLLVMObj(ejsval val)
 {
     if (EJSVAL_IS_NULL(val)) return NULL;
     return ((StructType*)EJSVAL_TO_OBJECT(val))->type;
 }
Пример #6
0
int
_ejs_op_foo(ejsval exp)
{
    return (EJSVAL_IS_NULL(exp) || EJSVAL_IS_UNDEFINED(exp)) ? 1 : 0;
}
Пример #7
0
 llvm::AllocaInst*
 AllocaInst_GetLLVMObj(ejsval val)
 {
     if (EJSVAL_IS_NULL(val)) return NULL;
     return ((AllocaInst*)EJSVAL_TO_OBJECT(val))->llvm_alloca;
 }
Пример #8
0
ejsval
_ejs_op_typeof_is_null(ejsval exp)
{
    return EJSVAL_IS_NULL(exp) ? _ejs_true : _ejs_false;
}
Пример #9
0
 llvm::LandingPadInst*
 LandingPad_GetLLVMObj(ejsval val)
 {
     if (EJSVAL_IS_NULL(val)) return NULL;
     return ((LandingPad*)EJSVAL_TO_OBJECT(val))->llvm_landing_pad;
 }
Пример #10
0
 llvm::ArrayType*
 ArrayType_GetLLVMObj(ejsval val)
 {
     if (EJSVAL_IS_NULL(val)) return NULL;
     return ((ArrayType*)EJSVAL_TO_OBJECT(val))->type;
 }
Пример #11
0
 llvm::BasicBlock*
 BasicBlock_GetLLVMObj(ejsval val)
 {
     if (EJSVAL_IS_NULL(val)) return NULL;
     return ((BasicBlock*)EJSVAL_TO_OBJECT(val))->llvm_bb;
 }
Пример #12
0
// ECMA262 15.3.4.3
static ejsval
_ejs_Function_prototype_apply (ejsval env, ejsval _this, uint32_t argc, ejsval *args)
{
    ejsval func = _this;

    /* 1. If IsCallable(func) is false, then throw a TypeError exception. */
    if (!EJSVAL_IS_CALLABLE(_this)) {
        printf ("throw TypeError, func is not callable\n");
        EJS_NOT_IMPLEMENTED();
    }

    ejsval thisArg = _ejs_undefined;
    ejsval argArray = _ejs_undefined;
    if (argc > 0) thisArg = args[0];
    if (argc > 1) argArray = args[1];

    /* 2. If argArray is null or undefined, then */
    if (EJSVAL_IS_UNDEFINED(argArray) || EJSVAL_IS_NULL(argArray)) {
        /*    a. Return the result of calling the [[Call]] internal method of func, providing thisArg as the this value */
        /*       and an empty list of arguments. */
        return _ejs_invoke_closure (func, thisArg, 0, NULL);
    }
    /* 3. If Type(argArray) is not Object, then throw a TypeError exception. */
    if (!EJSVAL_IS_OBJECT(argArray)) {
        printf ("throw TypeError, argArray is not an object\n");
        EJS_NOT_IMPLEMENTED();
    }
    EJSObject* argArray_ = EJSVAL_TO_OBJECT(argArray);

    /* 4. Let len be the result of calling the [[Get]] internal method of argArray with argument "length". */
    ejsval len = OP(argArray_,get) (argArray, _ejs_atom_length, argArray);

    /* 5. Let n be ToUint32(len). */
    uint32_t n = (uint32_t)EJSVAL_TO_NUMBER(len);

    /* 6. Let argList be an empty List. */
    ejsval* argList = (ejsval*)malloc(sizeof(ejsval) * n);

    /* 7. Let index be 0. */
    int index = 0;

    /* 8. Repeat while index < n */
    while (index < n) {
        /*    a. Let indexName be ToString(index). */
        ejsval indexName = NUMBER_TO_EJSVAL(index);
        /*    b. Let nextArg be the result of calling the [[Get]] internal method of argArray with indexName as the  */
        /*       argument. */
        ejsval nextArg = OP(argArray_,get)(argArray, indexName, argArray);
        /*    c. Append nextArg as the last element of argList. */
        argList[index] = nextArg;
        /*    d. Set index to index + 1. */
        ++index;
    }

    /* 9. Return the result of calling the [[Call]] internal method of func, providing thisArg as the this value and */
    /*    argList as the list of arguments. */
    ejsval rv = EJSVAL_TO_FUNC(func) (EJSVAL_TO_ENV(func), thisArg, n, argList);

    free (argList);
    return rv;
}