Class: Johnson::SpiderMonkey::ImmutableNode

Inherits:
Object
  • Object
show all
Defined in:
lib/johnson/spidermonkey/immutable_node.rb,
ext/spidermonkey/immutable_node.c

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.parse_io(stream, filename = nil, line_number = 0) ⇒ Object

Parses an IO object, returning a native spidermonkey parse tree.



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'ext/spidermonkey/immutable_node.c', line 36

static VALUE parse_io(int argc, VALUE *argv, VALUE klass) {
  VALUE self = allocate(klass);
  VALUE stream, filename, linenum;

  ImmutableNodeContext* context;
  Data_Get_Struct(self, ImmutableNodeContext, context);

  assert(context->pc = calloc(1L, sizeof(JSParseContext)));

  rb_scan_args( argc, argv, "12", &stream, &filename, &linenum );
  
  VALUE file_contents = rb_funcall(stream, rb_intern("read"), 0);
  size_t length = NUM2INT(rb_funcall(file_contents, rb_intern("length"), 0));

  jschar* chars;
  assert(chars = js_InflateString(context->js, StringValuePtr(file_contents), &length));

  if(!filename && rb_respond_to(stream, rb_intern("path"))) {
    filename = rb_funcall(stream, rb_intern("path"), 0);
  }
  char* filenamez = RTEST(filename) ? StringValueCStr(filename) : NULL;
  int linenumi = RTEST(linenum) ? NUM2INT(linenum) : 1;

  assert(js_InitParseContext(context->js, context->pc, 
      NULL,
      chars,
      length,
      NULL, filenamez, (unsigned)linenumi));
  JS_SetVersion(context->js, JSVERSION_LATEST);

  context->node = js_ParseScript(context->js, 
      JS_NewObject(context->js, NULL, NULL, NULL),
      context->pc);
  if(JS_IsExceptionPending(context->js)) {
    jsval exception, message, file_name, line_number;
    JS_GetPendingException(context->js, &exception);
    JS_GetProperty(context->js, JSVAL_TO_OBJECT(exception), "message",&message);
    JS_GetProperty(context->js, JSVAL_TO_OBJECT(exception), "fileName",&file_name);
    JS_GetProperty(context->js, JSVAL_TO_OBJECT(exception), "lineNumber",&line_number);
    JS_ClearPendingException(context->js);

    rb_funcall( self,
                rb_intern("raise_parse_error"),
                3,
                message == JSVAL_NULL ? 
                  Qnil :
                  rb_str_new2(JS_GetStringBytes(JSVAL_TO_STRING(message))),
                rb_str_new2(JS_GetStringBytes(JSVAL_TO_STRING(file_name))),
                INT2NUM((long)JSVAL_TO_INT(line_number))
                );

  }
  return self;
}

Instance Method Details

#accept(visitor) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/johnson/spidermonkey/immutable_node.rb', line 4

def accept(visitor)
  case pn_arity
  when :pn_list
    handle_list(visitor)
  when :pn_name
    if pn_expr
      m = {
        :tok_colon  => :visit_Label,
        :tok_name   => :visit_AssignExpr,
        :tok_dot    => :visit_DotAccessor,
        :tok_lexicalscope => :visit_LexicalScope
      }[pn_type]
      raise "Unknown type #{pn_type}" unless m
      visitor.send(m, self)
    else
      visitor.visit_Name(self)
    end
  when :pn_binary
    handle_binary(visitor)
  when :pn_unary
    handle_unary(visitor)
  when :pn_nullary
    handle_nullary(visitor)
  when :pn_func
    visitor.visit_Function(self)
  when :pn_ternary
    m = {
      :tok_hook   => :visit_Ternary,
      :tok_if     => :visit_If,
      :tok_try    => :visit_Try,
      :tok_catch  => :visit_Catch,
    }[pn_type]
    raise "Unknown ternary #{pn_type}" unless m
    visitor.send(m, self)
  else
    raise "unkown arity: #{pn_arity}"
  end
end

#childrenObject

Returns children as an Array of ImmutableNode.



634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
# File 'ext/spidermonkey/immutable_node.c', line 634

static VALUE children(VALUE self) {
  ImmutableNodeContext * ctx;
  JSParseNode * p;
  VALUE children;

  Data_Get_Struct(self, ImmutableNodeContext, ctx);
  children = rb_ary_new();
  for(p = ctx->node->pn_head; p != NULL; p = p->pn_next) {
    ImmutableNodeContext *roc;
    VALUE node = Data_Make_Struct(cNode, ImmutableNodeContext, NULL, NULL, roc);
    roc->js = ctx->js;
    roc->node = p;

    rb_ary_push(children, node);
  }

  return children;
}

#function_argsObject

Returns the function argument names as an Array of String.



557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
# File 'ext/spidermonkey/immutable_node.c', line 557

static VALUE function_args(VALUE self) {
  ImmutableNodeContext * ctx;
  JSFunction * f;
  JSObject * object;
  jsuword* names;
  VALUE func_args;
  int i;

  Data_Get_Struct(self, ImmutableNodeContext, ctx);
  object = ctx->node->pn_funpob->object;
  f = (JSFunction *)JS_GetPrivate(ctx->js, ctx->node->pn_funpob->object);

  func_args = rb_ary_new2((long)f->nargs);
  if(f->nargs > 0) {
    names = js_GetLocalNameArray(ctx->js, f, &ctx->js->tempPool);
    for(i = 0; i < f->nargs; i++) {
      rb_ary_push(func_args,
          rb_str_new2(JS_GetStringBytes(ATOM_TO_STRING(names[i])))
          );
    }
  }
  return func_args;
}

#function_bodyObject

Returns the function body as an ImmutableNode.



587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
# File 'ext/spidermonkey/immutable_node.c', line 587

static VALUE function_body(VALUE self) {
  ImmutableNodeContext * ctx;
  JSFunction * f;
  JSObject * object;

  Data_Get_Struct(self, ImmutableNodeContext, ctx);
  object = ctx->node->pn_funpob->object;
  f = (JSFunction *)JS_GetPrivate(ctx->js, ctx->node->pn_funpob->object);

  if(ctx->node->pn_body) {
    ImmutableNodeContext *roc;
    VALUE node = Data_Make_Struct(cNode, ImmutableNodeContext, NULL, NULL, roc);
    roc->js = ctx->js;
    roc->node = ctx->node->pn_body;
    return node;
  }
  return Qnil;
}

#function_nameObject

Returns the function name as a String.



535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
# File 'ext/spidermonkey/immutable_node.c', line 535

static VALUE function_name(VALUE self) {
  ImmutableNodeContext * ctx;
  JSFunction * f;
  JSObject * object;

  Data_Get_Struct(self, ImmutableNodeContext, ctx);
  object = ctx->node->pn_funpob->object;
  f = (JSFunction *)JS_GetPrivate(ctx->js, ctx->node->pn_funpob->object);

  if(f->atom) {
    return rb_str_new2(JS_GetStringBytes(ATOM_TO_STRING(f->atom)));
  } else {
    return Qnil;
  }
}

#indexObject

Returns the column number of the node.



110
111
112
113
114
115
# File 'ext/spidermonkey/immutable_node.c', line 110

static VALUE begin_index(VALUE self) {
  ImmutableNodeContext * ctx;

  Data_Get_Struct(self, ImmutableNodeContext, ctx);
  return INT2NUM((long)(ctx->node->pn_pos.begin.index));
}

#lineObject

Returns the line number of the node.



97
98
99
100
101
102
# File 'ext/spidermonkey/immutable_node.c', line 97

static VALUE line(VALUE self) {
  ImmutableNodeContext * ctx;

  Data_Get_Struct(self, ImmutableNodeContext, ctx);
  return INT2NUM((long)(ctx->node->pn_pos.begin.lineno));
}

#nameObject

Returns the name of the node.



507
508
509
510
511
512
# File 'ext/spidermonkey/immutable_node.c', line 507

static VALUE name(VALUE self) {
  ImmutableNodeContext * ctx;

  Data_Get_Struct(self, ImmutableNodeContext, ctx);
  return rb_str_new2(JS_GetStringBytes(ATOM_TO_STRING(ctx->node->pn_atom)));
}

#pn_arityObject

Returns the arity of the node as a symbol.



123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'ext/spidermonkey/immutable_node.c', line 123

static VALUE pn_arity(VALUE self) {
  ImmutableNodeContext * ctx;

  Data_Get_Struct(self, ImmutableNodeContext, ctx);
  switch(ctx->node->pn_arity) {
    case PN_FUNC:
      return ID2SYM(rb_intern("pn_func"));
    case PN_LIST:
      return ID2SYM(rb_intern("pn_list"));
    case PN_TERNARY:
      return ID2SYM(rb_intern("pn_ternary"));
    case PN_BINARY:
      return ID2SYM(rb_intern("pn_binary"));
    case PN_UNARY:
      return ID2SYM(rb_intern("pn_unary"));
    case PN_NAME:
      return ID2SYM(rb_intern("pn_name"));
    case PN_NULLARY:
      return ID2SYM(rb_intern("pn_nullary"));
  }
  return Qnil;
}

#pn_dvalObject

Returns the numeric value of the node.



442
443
444
445
446
447
448
449
450
451
# File 'ext/spidermonkey/immutable_node.c', line 442

static VALUE data_pn_dval(VALUE self) {
  ImmutableNodeContext * ctx;

  Data_Get_Struct(self, ImmutableNodeContext, ctx);
  if(JSVAL_IS_NUMBER(ATOM_KEY(ctx->node->pn_atom))) {
    return rb_float_new(ctx->node->pn_dval);
  } else {
    return INT2NUM((long)(ctx->node->pn_dval));
  }
}

#pn_exprObject

Returns the parse node expression as an ImmutableNode.



342
343
344
345
346
347
348
349
350
351
352
353
354
# File 'ext/spidermonkey/immutable_node.c', line 342

static VALUE data_pn_expr(VALUE self) {
  ImmutableNodeContext * ctx;

  Data_Get_Struct(self, ImmutableNodeContext, ctx);
  if(ctx->node->pn_expr) {
    ImmutableNodeContext *roc;
    VALUE node = Data_Make_Struct(cNode, ImmutableNodeContext, NULL, NULL, roc);
    roc->js = ctx->js;
    roc->node = ctx->node->pn_expr;
    return node;
  }
  return Qnil;
}

#pn_extraObject

Returns extra informaton about the node as an Integer.



493
494
495
496
497
498
499
# File 'ext/spidermonkey/immutable_node.c', line 493

static VALUE data_pn_extra(VALUE self) {
  ImmutableNodeContext * ctx;

  Data_Get_Struct(self, ImmutableNodeContext, ctx);

  return UINT2NUM((unsigned long)(ctx->node->pn_extra));
}

#pn_kidObject

Returns the child ImmutableNode.



362
363
364
365
366
367
368
369
370
371
372
373
374
# File 'ext/spidermonkey/immutable_node.c', line 362

static VALUE data_pn_kid(VALUE self) {
  ImmutableNodeContext * ctx;

  Data_Get_Struct(self, ImmutableNodeContext, ctx);
  if(ctx->node->pn_kid) {
    ImmutableNodeContext *roc;
    VALUE node = Data_Make_Struct(cNode, ImmutableNodeContext, NULL, NULL, roc);
    roc->js = ctx->js;
    roc->node = ctx->node->pn_kid;
    return node;
  }
  return Qnil;
}

#pn_kid1Object

Returns the first child ImmutableNode.



382
383
384
385
386
387
388
389
390
391
392
393
394
# File 'ext/spidermonkey/immutable_node.c', line 382

static VALUE data_pn_kid1(VALUE self) {
  ImmutableNodeContext * ctx;

  Data_Get_Struct(self, ImmutableNodeContext, ctx);
  if(ctx->node->pn_kid1) {
    ImmutableNodeContext *roc;
    VALUE node = Data_Make_Struct(cNode, ImmutableNodeContext, NULL, NULL, roc);
    roc->js = ctx->js;
    roc->node = ctx->node->pn_kid1;
    return node;
  }
  return Qnil;
}

#pn_kid2Object

Returns the second child ImmutableNode.



402
403
404
405
406
407
408
409
410
411
412
413
414
# File 'ext/spidermonkey/immutable_node.c', line 402

static VALUE data_pn_kid2(VALUE self) {
  ImmutableNodeContext * ctx;

  Data_Get_Struct(self, ImmutableNodeContext, ctx);
  if(ctx->node->pn_kid2) {
    ImmutableNodeContext *roc;
    VALUE node = Data_Make_Struct(cNode, ImmutableNodeContext, NULL, NULL, roc);
    roc->js = ctx->js;
    roc->node = ctx->node->pn_kid2;
    return node;
  }
  return Qnil;
}

#pn_kid3Object

Returns the third child ImmutableNode.



422
423
424
425
426
427
428
429
430
431
432
433
434
# File 'ext/spidermonkey/immutable_node.c', line 422

static VALUE data_pn_kid3(VALUE self) {
  ImmutableNodeContext * ctx;

  Data_Get_Struct(self, ImmutableNodeContext, ctx);
  if(ctx->node->pn_kid3) {
    ImmutableNodeContext *roc;
    VALUE node = Data_Make_Struct(cNode, ImmutableNodeContext, NULL, NULL, roc);
    roc->js = ctx->js;
    roc->node = ctx->node->pn_kid3;
    return node;
  }
  return Qnil;
}

#pn_leftObject

Returns the left side ImmutableNode.



472
473
474
475
476
477
478
479
480
481
482
483
484
485
# File 'ext/spidermonkey/immutable_node.c', line 472

static VALUE data_pn_left(VALUE self) {
  ImmutableNodeContext * ctx;

  Data_Get_Struct(self, ImmutableNodeContext, ctx);

  if(ctx->node->pn_left) {
    ImmutableNodeContext *roc;
    VALUE node = Data_Make_Struct(cNode, ImmutableNodeContext, NULL, NULL, roc);
    roc->js = ctx->js;
    roc->node = ctx->node->pn_left;
    return node;
  }
  return Qnil;
}

#pn_opObject

Returns the op code for the node as a symbol.



459
460
461
462
463
464
# File 'ext/spidermonkey/immutable_node.c', line 459

static VALUE data_pn_op(VALUE self) {
  ImmutableNodeContext * ctx;

  Data_Get_Struct(self, ImmutableNodeContext, ctx);
  return jsop_to_symbol(ctx->node->pn_op);
}

#pn_rightObject

Returns right side as an ImmutableNode.



612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
# File 'ext/spidermonkey/immutable_node.c', line 612

static VALUE data_pn_right(VALUE self)
{
  ImmutableNodeContext * ctx;

  Data_Get_Struct(self, ImmutableNodeContext, ctx);

  if(ctx->node->pn_right) {
    ImmutableNodeContext *roc;
    VALUE node = Data_Make_Struct(cNode, ImmutableNodeContext, NULL, NULL, roc);
    roc->js = ctx->js;
    roc->node = ctx->node->pn_right;
    return node;
  }
  return Qnil;
}

#pn_typeObject

Returns the type of the node as a symbol.



152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
# File 'ext/spidermonkey/immutable_node.c', line 152

static VALUE pn_type(VALUE self) {
  ImmutableNodeContext * ctx;

  Data_Get_Struct(self, ImmutableNodeContext, ctx);
  switch(ctx->node->pn_type) {
    
    case TOK_EOF: return ID2SYM(rb_intern("tok_eof"));
    
    case TOK_EOL: return ID2SYM(rb_intern("tok_eol"));
    
    case TOK_SEMI: return ID2SYM(rb_intern("tok_semi"));
    
    case TOK_COMMA: return ID2SYM(rb_intern("tok_comma"));
    
    case TOK_ASSIGN: return ID2SYM(rb_intern("tok_assign"));
    
    case TOK_HOOK: return ID2SYM(rb_intern("tok_hook"));
    
    case TOK_COLON: return ID2SYM(rb_intern("tok_colon"));
    
    case TOK_OR: return ID2SYM(rb_intern("tok_or"));
    
    case TOK_AND: return ID2SYM(rb_intern("tok_and"));
    
    case TOK_BITOR: return ID2SYM(rb_intern("tok_bitor"));
    
    case TOK_BITXOR: return ID2SYM(rb_intern("tok_bitxor"));
    
    case TOK_BITAND: return ID2SYM(rb_intern("tok_bitand"));
    
    case TOK_EQOP: return ID2SYM(rb_intern("tok_eqop"));
    
    case TOK_RELOP: return ID2SYM(rb_intern("tok_relop"));
    
    case TOK_SHOP: return ID2SYM(rb_intern("tok_shop"));
    
    case TOK_PLUS: return ID2SYM(rb_intern("tok_plus"));
    
    case TOK_MINUS: return ID2SYM(rb_intern("tok_minus"));
    
    case TOK_STAR: return ID2SYM(rb_intern("tok_star"));
    
    case TOK_DIVOP: return ID2SYM(rb_intern("tok_divop"));
    
    case TOK_UNARYOP: return ID2SYM(rb_intern("tok_unaryop"));
    
    case TOK_INC: return ID2SYM(rb_intern("tok_inc"));
    
    case TOK_DEC: return ID2SYM(rb_intern("tok_dec"));
    
    case TOK_DOT: return ID2SYM(rb_intern("tok_dot"));
    
    case TOK_LB: return ID2SYM(rb_intern("tok_lb"));
    
    case TOK_RB: return ID2SYM(rb_intern("tok_rb"));
    
    case TOK_LC: return ID2SYM(rb_intern("tok_lc"));
    
    case TOK_RC: return ID2SYM(rb_intern("tok_rc"));
    
    case TOK_LP: return ID2SYM(rb_intern("tok_lp"));
    
    case TOK_RP: return ID2SYM(rb_intern("tok_rp"));
    
    case TOK_NAME: return ID2SYM(rb_intern("tok_name"));
    
    case TOK_NUMBER: return ID2SYM(rb_intern("tok_number"));
    
    case TOK_STRING: return ID2SYM(rb_intern("tok_string"));
    
    case TOK_REGEXP: return ID2SYM(rb_intern("tok_regexp"));
    
    case TOK_PRIMARY: return ID2SYM(rb_intern("tok_primary"));
    
    case TOK_FUNCTION: return ID2SYM(rb_intern("tok_function"));
    
    case TOK_EXPORT: return ID2SYM(rb_intern("tok_export"));
    
    case TOK_IMPORT: return ID2SYM(rb_intern("tok_import"));
    
    case TOK_IF: return ID2SYM(rb_intern("tok_if"));
    
    case TOK_ELSE: return ID2SYM(rb_intern("tok_else"));
    
    case TOK_SWITCH: return ID2SYM(rb_intern("tok_switch"));
    
    case TOK_CASE: return ID2SYM(rb_intern("tok_case"));
    
    case TOK_DEFAULT: return ID2SYM(rb_intern("tok_default"));
    
    case TOK_WHILE: return ID2SYM(rb_intern("tok_while"));
    
    case TOK_DO: return ID2SYM(rb_intern("tok_do"));
    
    case TOK_FOR: return ID2SYM(rb_intern("tok_for"));
    
    case TOK_BREAK: return ID2SYM(rb_intern("tok_break"));
    
    case TOK_CONTINUE: return ID2SYM(rb_intern("tok_continue"));
    
    case TOK_IN: return ID2SYM(rb_intern("tok_in"));
    
    case TOK_VAR: return ID2SYM(rb_intern("tok_var"));
    
    case TOK_WITH: return ID2SYM(rb_intern("tok_with"));
    
    case TOK_RETURN: return ID2SYM(rb_intern("tok_return"));
    
    case TOK_NEW: return ID2SYM(rb_intern("tok_new"));
    
    case TOK_DELETE: return ID2SYM(rb_intern("tok_delete"));
    
    case TOK_DEFSHARP: return ID2SYM(rb_intern("tok_defsharp"));
    
    case TOK_USESHARP: return ID2SYM(rb_intern("tok_usesharp"));
    
    case TOK_TRY: return ID2SYM(rb_intern("tok_try"));
    
    case TOK_CATCH: return ID2SYM(rb_intern("tok_catch"));
    
    case TOK_FINALLY: return ID2SYM(rb_intern("tok_finally"));
    
    case TOK_THROW: return ID2SYM(rb_intern("tok_throw"));
    
    case TOK_INSTANCEOF: return ID2SYM(rb_intern("tok_instanceof"));
    
    case TOK_DEBUGGER: return ID2SYM(rb_intern("tok_debugger"));
    
    case TOK_XMLSTAGO: return ID2SYM(rb_intern("tok_xmlstago"));
    
    case TOK_XMLETAGO: return ID2SYM(rb_intern("tok_xmletago"));
    
    case TOK_XMLPTAGC: return ID2SYM(rb_intern("tok_xmlptagc"));
    
    case TOK_XMLTAGC: return ID2SYM(rb_intern("tok_xmltagc"));
    
    case TOK_XMLNAME: return ID2SYM(rb_intern("tok_xmlname"));
    
    case TOK_XMLATTR: return ID2SYM(rb_intern("tok_xmlattr"));
    
    case TOK_XMLSPACE: return ID2SYM(rb_intern("tok_xmlspace"));
    
    case TOK_XMLTEXT: return ID2SYM(rb_intern("tok_xmltext"));
    
    case TOK_XMLCOMMENT: return ID2SYM(rb_intern("tok_xmlcomment"));
    
    case TOK_XMLCDATA: return ID2SYM(rb_intern("tok_xmlcdata"));
    
    case TOK_XMLPI: return ID2SYM(rb_intern("tok_xmlpi"));
    
    case TOK_AT: return ID2SYM(rb_intern("tok_at"));
    
    case TOK_DBLCOLON: return ID2SYM(rb_intern("tok_dblcolon"));
    
    case TOK_ANYNAME: return ID2SYM(rb_intern("tok_anyname"));
    
    case TOK_DBLDOT: return ID2SYM(rb_intern("tok_dbldot"));
    
    case TOK_FILTER: return ID2SYM(rb_intern("tok_filter"));
    
    case TOK_XMLELEM: return ID2SYM(rb_intern("tok_xmlelem"));
    
    case TOK_XMLLIST: return ID2SYM(rb_intern("tok_xmllist"));
    
    case TOK_YIELD: return ID2SYM(rb_intern("tok_yield"));
    
    case TOK_ARRAYCOMP: return ID2SYM(rb_intern("tok_arraycomp"));
    
    case TOK_ARRAYPUSH: return ID2SYM(rb_intern("tok_arraypush"));
    
    case TOK_LEXICALSCOPE: return ID2SYM(rb_intern("tok_lexicalscope"));
    
    case TOK_LET: return ID2SYM(rb_intern("tok_let"));
    
    case TOK_BODY: return ID2SYM(rb_intern("tok_body"));
    
    case TOK_RESERVED: return ID2SYM(rb_intern("tok_reserved"));
    
    case TOK_LIMIT: return ID2SYM(rb_intern("tok_limit"));
    
  }
  return INT2NUM((long)(ctx->node->pn_type));
}

#regexpObject

Returns the regexp value as a String.



520
521
522
523
524
525
526
527
# File 'ext/spidermonkey/immutable_node.c', line 520

static VALUE regexp(VALUE self) {
  ImmutableNodeContext * ctx;
  jsval result;

  Data_Get_Struct(self, ImmutableNodeContext, ctx);
  js_regexp_toString(ctx->js, ctx->node->pn_pob->object, &result);
  return rb_str_new2(JS_GetStringBytes(JSVAL_TO_STRING(result)));
}

#to_mutable_treeObject



43
44
45
# File 'lib/johnson/spidermonkey/immutable_node.rb', line 43

def to_mutable_tree
  MutableTreeVisitor.new.accept(self)
end

#to_sexpObject



47
48
49
# File 'lib/johnson/spidermonkey/immutable_node.rb', line 47

def to_sexp
  to_mutable_tree.to_sexp
end