Browse Source

Add __defineGetter__() and __defineSetter__()

pull/1531/head
Sami Vaarala 8 years ago
parent
commit
3a2016c15a
  1. 20
      src-input/builtins.yaml
  2. 23
      src-input/duk_bi_object.c

20
src-input/builtins.yaml

@ -699,6 +699,26 @@ objects:
length: 1
present_if: DUK_USE_OBJECT_BUILTIN
# __defineGetter, __defineSetter__: ES2018 draft Annex B
# https://tc39.github.io/ecma262/#sec-additional-properties-of-the-object.prototype-object
# https://tc39.github.io/ecma262/#sec-object.prototype.__defineGetter__
# https://tc39.github.io/ecma262/#sec-object.prototype.__defineSetter__
- key: "__defineGetter__"
value:
type: function
native: duk_bi_object_prototype_defineaccessor
length: 2
magic: 0 # define getter
present_if: DUK_USE_ES8
- key: "__defineSetter__"
value:
type: function
native: duk_bi_object_prototype_defineaccessor
length: 2
magic: 1 # define setter
present_if: DUK_USE_ES8
- id: bi_function_constructor
class: Function
internal_prototype: bi_function_prototype

23
src-input/duk_bi_object.c

@ -805,3 +805,26 @@ DUK_INTERNAL duk_ret_t duk_bi_object_constructor_prevent_extensions(duk_context
return 1;
}
#endif /* DUK_USE_OBJECT_BUILTIN || DUK_USE_REFLECT_BUILTIN */
/*
* __defineGetter__, __defineSetter__
*/
#if defined(DUK_USE_ES8)
DUK_INTERNAL duk_ret_t duk_bi_object_prototype_defineaccessor(duk_context *ctx) {
duk_push_this(ctx);
duk_insert(ctx, 0);
duk_to_object(ctx, 0);
if (!duk_is_callable(ctx, 2)) {
DUK_DCERROR_TYPE_INVALID_ARGS((duk_hthread *) ctx);
}
/* [ ToObject(this) key getter/setter ] */
/* ToPropertyKey() coercion is not needed, duk_def_prop() does it. */
duk_def_prop(ctx, 0, DUK_DEFPROP_SET_ENUMERABLE |
DUK_DEFPROP_SET_CONFIGURABLE |
(duk_get_current_magic(ctx) ? DUK_DEFPROP_HAVE_SETTER : DUK_DEFPROP_HAVE_GETTER));
return 0;
}
#endif /* DUK_USE_ES8 */

Loading…
Cancel
Save