Exemplo n.º 1
0
// ECMA262 25.4.4.6 Promise [ @@create ] ( )
static ejsval
_ejs_Promise_create (ejsval env, ejsval _this, uint32_t argc, ejsval *args)
{
    // 1. Let F be the this value
    ejsval F = _this;

    // 2. Return AllocatePromise(F). 
    //    1. Let obj be OrdinaryCreateFromConstructor(constructor, "%PromisePrototype%", ([[PromiseState]], [[PromiseConstructor]], [[PromiseResult]], [[PromiseFulfillReactions]], [[PromiseRejectReactions]]) ). 
    ejsval proto = _ejs_undefined;
    if (!EJSVAL_IS_UNDEFINED(F)) {
        if (!EJSVAL_IS_CONSTRUCTOR(F))
            _ejs_throw_nativeerror_utf8 (EJS_TYPE_ERROR, "'this' in Promise[Symbol.create] is not a constructor");

        EJSObject* F_ = EJSVAL_TO_OBJECT(F);

        proto = OP(F_,Get)(F, _ejs_atom_prototype, F);
    }
    if (EJSVAL_IS_UNDEFINED(proto))
        proto = _ejs_Promise_prototype;

    EJSObject* obj = (EJSObject*)_ejs_gc_new (EJSPromise);
    _ejs_init_object (obj, proto, &_ejs_Promise_specops);

    //    2. Set the value of obj’s [[PromiseConstructor]] internal slot to constructor. 
    ((EJSPromise*)obj)->constructor = F;

    //    3. Return obj. 
    return OBJECT_TO_EJSVAL(obj);
}
Exemplo n.º 2
0
    static ejsval
    Module_create (ejsval env, ejsval _this, int argc, ejsval *args)
    {
        ejsval F = _this;
        if (!EJSVAL_IS_CONSTRUCTOR(F)) 
            _ejs_throw_nativeerror_utf8 (EJS_TYPE_ERROR, "'this' in Module[Symbol.create] is not a constructor");
        EJSObject* F_ = EJSVAL_TO_OBJECT(F);
        // 2. Let obj be the result of calling OrdinaryCreateFromConstructor(F, "%DatePrototype%", ([[DateData]]) ). 
        ejsval proto = OP(F_,Get)(F, _ejs_atom_prototype, F);
        if (EJSVAL_IS_UNDEFINED(proto))
            proto = _ejs_Module_prototype;

        EJSObject* obj = (EJSObject*)_ejs_gc_new (Module);
        _ejs_init_object (obj, proto, &_ejs_Module_specops);
        return OBJECT_TO_EJSVAL(obj);
    }
Exemplo n.º 3
0
static ejsval
_ejs_Function_prototype_create(ejsval env, ejsval _this, uint32_t argc, ejsval* args)
{
    ejsval F = _this;

    if (!EJSVAL_IS_CONSTRUCTOR(F)) 
        _ejs_throw_nativeerror_utf8 (EJS_TYPE_ERROR, "'this' in Function.prototype[Symbol.create] is not a constructor");
        
    EJSObject* F_ = EJSVAL_TO_OBJECT(F);

    ejsval proto = OP(F_,Get)(F, _ejs_atom_prototype, F);
    if (EJSVAL_IS_UNDEFINED(proto)) {
        proto = _ejs_Function_prototype;
    }

    if (!EJSVAL_IS_OBJECT(proto)) {
        EJS_NOT_IMPLEMENTED(); // cross-realm doesn't exist in ejs yet
    }

    EJSObject* obj = (EJSObject*)_ejs_gc_new (EJSObject);
    _ejs_init_object (obj, proto, &_ejs_Object_specops);
    return OBJECT_TO_EJSVAL(obj);
}
Exemplo n.º 4
0
static ejsval
_ejs_RegExp_create (ejsval env, ejsval _this, uint32_t argc, ejsval *args)
{
    // 1. Let F be the this value. 
    ejsval F = _this;

    if (!EJSVAL_IS_CONSTRUCTOR(F)) 
        _ejs_throw_nativeerror_utf8 (EJS_TYPE_ERROR, "'this' in RegExp[Symbol.create] is not a constructor");

    EJSObject* F_ = EJSVAL_TO_OBJECT(F);

    // 2. Let obj be the result of calling OrdinaryCreateFromConstructor(constructor, "%RegExpPrototype%", ( [[RegExpMatcher]], [[OriginalSource]], [[OriginalFlags]])). 
    ejsval proto = OP(F_,Get)(F, _ejs_atom_prototype, F);
    if (EJSVAL_IS_UNDEFINED(proto))
        proto = _ejs_RegExp_prototype;

    EJSRegExp* re = (EJSRegExp*)_ejs_gc_new (EJSRegExp);
    _ejs_init_object ((EJSObject*)re, proto, &_ejs_RegExp_specops);
    
    re->pattern = _ejs_undefined;
    re->flags = _ejs_undefined;

    return OBJECT_TO_EJSVAL((EJSObject*)re);
}