njs_token_t
njs_parser_terminal(njs_vm_t *vm, njs_parser_t *parser, njs_token_t token)
{
- double num;
- njs_ret_t ret;
- njs_value_t *ext;
- njs_parser_node_t *node;
+ double num;
+ njs_ret_t ret;
+ njs_value_t *ext;
+ njs_parser_node_t *node;
+ njs_parser_scope_t *scope;
if (token == NJS_TOKEN_OPEN_PARENTHESIS) {
case NJS_TOKEN_THIS:
nxt_thread_log_debug("JS: this");
- if (parser->scope->type != NJS_SCOPE_GLOBAL) {
- node->index = NJS_INDEX_THIS;
+ scope = parser->scope;
+
+ while (scope->type != NJS_SCOPE_GLOBAL) {
+ if (scope->type == NJS_SCOPE_FUNCTION) {
+ node->index = NJS_INDEX_THIS;
+ break;
+ }
+
+ scope = scope->parent;
+ }
+
+ if (node->index == NJS_INDEX_THIS) {
break;
}
{ nxt_string("/./ instanceof Object"),
nxt_string("true") },
+ /* global this. */
+
{ nxt_string("this"),
nxt_string("[object Object]") },
{ nxt_string("this.NaN + 1"),
nxt_string("NaN") },
+ { nxt_string("if (1) {new this}"),
+ nxt_string("TypeError: object is not a function") },
+
+ { nxt_string("if (1) {this()}"),
+ nxt_string("TypeError: object is not a function") },
+
+ { nxt_string("var ex; try {new this} catch (e) {ex = e}; ex"),
+ nxt_string("TypeError: object is not a function") },
+
+ { nxt_string("var ex; try {({}) instanceof this} catch (e) {ex = e}; ex"),
+ nxt_string("TypeError: right argument is not a function") },
+
+ { nxt_string("Function.call(this, 'var x / = 1;')"),
+ nxt_string("InternalError: Not implemented") },
+
{ nxt_string("njs"),
nxt_string("[object Object]") },