Added new target support to Promise (#3707)
JerryScript-DCO-1.0-Signed-off-by: bence gabor kis kisbg@inf.u-szeged.hu
This commit is contained in:
+11
-1
@@ -1616,7 +1616,17 @@ jerry_create_promise (void)
|
|||||||
jerry_assert_api_available ();
|
jerry_assert_api_available ();
|
||||||
|
|
||||||
#if ENABLED (JERRY_ES2015_BUILTIN_PROMISE)
|
#if ENABLED (JERRY_ES2015_BUILTIN_PROMISE)
|
||||||
return ecma_op_create_promise_object (ECMA_VALUE_EMPTY, ECMA_PROMISE_EXECUTOR_EMPTY);
|
ecma_object_t * old_new_target_p = JERRY_CONTEXT (current_new_target);
|
||||||
|
|
||||||
|
if (old_new_target_p == NULL)
|
||||||
|
{
|
||||||
|
JERRY_CONTEXT (current_new_target) = ecma_builtin_get (ECMA_BUILTIN_ID_PROMISE);
|
||||||
|
}
|
||||||
|
|
||||||
|
ecma_value_t promise_value = ecma_op_create_promise_object (ECMA_VALUE_EMPTY, ECMA_PROMISE_EXECUTOR_EMPTY);
|
||||||
|
|
||||||
|
JERRY_CONTEXT (current_new_target) = old_new_target_p;
|
||||||
|
return promise_value;
|
||||||
#else /* !ENABLED (JERRY_ES2015_BUILTIN_PROMISE) */
|
#else /* !ENABLED (JERRY_ES2015_BUILTIN_PROMISE) */
|
||||||
return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG ("Promise not supported.")));
|
return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG ("Promise not supported.")));
|
||||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROMISE) */
|
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROMISE) */
|
||||||
|
|||||||
@@ -493,11 +493,20 @@ ecma_value_t
|
|||||||
ecma_op_create_promise_object (ecma_value_t executor, /**< the executor function or object */
|
ecma_op_create_promise_object (ecma_value_t executor, /**< the executor function or object */
|
||||||
ecma_promise_executor_type_t type) /**< indicates the type of executor */
|
ecma_promise_executor_type_t type) /**< indicates the type of executor */
|
||||||
{
|
{
|
||||||
|
JERRY_ASSERT (JERRY_CONTEXT (current_new_target) != NULL);
|
||||||
/* 3. */
|
/* 3. */
|
||||||
ecma_object_t *prototype_obj_p = ecma_builtin_get (ECMA_BUILTIN_ID_PROMISE_PROTOTYPE);
|
ecma_object_t *proto_p = ecma_op_get_prototype_from_constructor (JERRY_CONTEXT (current_new_target),
|
||||||
ecma_object_t *object_p = ecma_create_object (prototype_obj_p,
|
ECMA_BUILTIN_ID_PROMISE_PROTOTYPE);
|
||||||
|
|
||||||
|
if (JERRY_UNLIKELY (proto_p == NULL))
|
||||||
|
{
|
||||||
|
return ECMA_VALUE_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
ecma_object_t *object_p = ecma_create_object (proto_p,
|
||||||
sizeof (ecma_promise_object_t),
|
sizeof (ecma_promise_object_t),
|
||||||
ECMA_OBJECT_TYPE_CLASS);
|
ECMA_OBJECT_TYPE_CLASS);
|
||||||
|
ecma_deref_object (proto_p);
|
||||||
ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) object_p;
|
ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) object_p;
|
||||||
ext_object_p->u.class_prop.class_id = LIT_MAGIC_STRING_PROMISE_UL;
|
ext_object_p->u.class_prop.class_id = LIT_MAGIC_STRING_PROMISE_UL;
|
||||||
ext_object_p->u.class_prop.u.value = ECMA_VALUE_UNDEFINED;
|
ext_object_p->u.class_prop.u.value = ECMA_VALUE_UNDEFINED;
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
/* Copyright JS Foundation and other contributors, http://js.foundation
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
try {
|
||||||
|
Reflect.construct (Promise);
|
||||||
|
assert (false);
|
||||||
|
} catch (e) {
|
||||||
|
assert (e instanceof TypeError);
|
||||||
|
}
|
||||||
|
|
||||||
|
class MyPromise extends Promise {};
|
||||||
|
|
||||||
|
var p1= new MyPromise(function(){});
|
||||||
|
assert(Object.getPrototypeOf(p1) == MyPromise.prototype)
|
||||||
Reference in New Issue
Block a user