Browse Source

add fileName and lineNumber accessors to Error.prototype; make stack, fileName, and lineNumber setter be an explicit nop

pull/1/head
Sami Vaarala 11 years ago
parent
commit
204900e13e
  1. 33
      src/duk_builtin_error.c
  2. 5
      src/duk_builtin_protos.h
  3. 10
      src/genbuiltins.py

33
src/duk_builtin_error.c

@ -105,10 +105,6 @@ int duk_builtin_error_prototype_to_string(duk_context *ctx) {
return DUK_RET_TYPE_ERROR;
}
/* FIXME: This needs to actually be a getter/setter pair, this is
* for prototyping traceback formatting. The resulting code is
* also way too large, so needs rework.
*/
int duk_builtin_error_prototype_stack_getter(duk_context *ctx) {
duk_hthread *thr = (duk_hthread *) ctx;
int idx_td;
@ -220,25 +216,18 @@ int duk_builtin_error_prototype_stack_getter(duk_context *ctx) {
return 1;
}
int duk_builtin_error_prototype_stack_setter(duk_context *ctx) {
/* At the moment, a silent no-op. */
DUK_ASSERT_TOP(ctx, 1); /* fixed arg count */
#if 0
/* Write an own 'stack' property with the new value, which then
* shadows the accessor.
*/
int duk_builtin_error_prototype_filename_getter(duk_context *ctx) {
return DUK_RET_UNIMPLEMENTED_ERROR;
}
/* FIXME: This would need to define an own property skipping the normal
* property protections. The current helpers for doing raw property
* setting bypass Ecmascript attribute semantics so they are not
* appropriate here. What's needed here is a helper for doing what
* Object.defineProperty() does but with a nice API. One could also
* simply check that 'this' has no own 'stack 'property' and only
* force the property to be defined in this case.
int duk_builtin_error_prototype_linenumber_getter(duk_context *ctx) {
return DUK_RET_UNIMPLEMENTED_ERROR;
}
int duk_builtin_error_prototype_nop_setter(duk_context *ctx) {
/* Attempt to write 'stack', 'fileName', 'lineNumber' is a silent no-op.
* User can use Object.defineProperty() to override this behavior.
*/
duk_push_this(ctx);
duk_insert(ctx, 0); /* -> [ this val ] */
duk_put_prop_stridx(ctx, -2, DUK_STRIDX_STACK);
#endif
DUK_ASSERT_TOP(ctx, 1); /* fixed arg count */
return 0;
}

5
src/duk_builtin_protos.h

@ -102,7 +102,10 @@ int duk_builtin_duk_object_sleep(duk_context *ctx);
int duk_builtin_error_constructor(duk_context *ctx);
int duk_builtin_error_prototype_to_string(duk_context *ctx);
int duk_builtin_error_prototype_stack_getter(duk_context *ctx);
int duk_builtin_error_prototype_stack_setter(duk_context *ctx);
int duk_builtin_error_prototype_filename_getter(duk_context *ctx);
int duk_builtin_error_prototype_linenumber_getter(duk_context *ctx);
int duk_builtin_error_prototype_stack_getter(duk_context *ctx);
int duk_builtin_error_prototype_nop_setter(duk_context *ctx);
int duk_builtin_eval_error_constructor(duk_context *ctx);
int duk_builtin_range_error_constructor(duk_context *ctx);
int duk_builtin_reference_error_constructor(duk_context *ctx);

10
src/genbuiltins.py

@ -771,11 +771,15 @@ bi_error_prototype = {
# Custom properties
# FIXME: custom properties
{ 'name': 'stack',
'getter': 'duk_builtin_error_prototype_stack_getter',
'setter': 'duk_builtin_error_prototype_stack_setter' },
'setter': 'duk_builtin_error_prototype_nop_setter' },
{ 'name': 'fileName',
'getter': 'duk_builtin_error_prototype_filename_getter',
'setter': 'duk_builtin_error_prototype_nop_setter' },
{ 'name': 'lineNumber',
'getter': 'duk_builtin_error_prototype_linenumber_getter',
'setter': 'duk_builtin_error_prototype_nop_setter' },
],
'functions': [
{ 'name': 'toString', 'native': 'duk_builtin_error_prototype_to_string', 'length': 0 },

Loading…
Cancel
Save