1 | // Copyright (C) 2008 Google Inc. |
2 | // |
3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
4 | // you may not use this file except in compliance with the License. |
5 | // You may obtain a copy of the License at |
6 | // |
7 | // http://www.apache.org/licenses/LICENSE-2.0 |
8 | // |
9 | // Unless required by applicable law or agreed to in writing, software |
10 | // distributed under the License is distributed on an "AS IS" BASIS, |
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 | // See the License for the specific language governing permissions and |
13 | // limitations under the License. |
14 | |
15 | package com.google.caja.parser.js; |
16 | |
17 | import com.google.caja.reporting.RenderContext; |
18 | import com.google.caja.lexer.FilePosition; |
19 | import com.google.caja.lexer.TokenConsumer; |
20 | import com.google.caja.parser.ParseTreeNode; |
21 | import com.google.javascript.jscomp.jsonml.JsonML; |
22 | import com.google.javascript.jscomp.jsonml.TagType; |
23 | |
24 | import java.util.List; |
25 | |
26 | /** |
27 | * A statement that is a noop in normal execution, but will trigger a breakpoint |
28 | * if a debugger is attached. |
29 | * |
30 | * @author mikesamuel@gmail.com |
31 | */ |
32 | public final class DebuggerStmt extends AbstractStatement { |
33 | /** |
34 | * This ctor is provided for reflection. |
35 | * @param value unused. |
36 | * @param children unused. |
37 | */ |
38 | @ReflectiveCtor |
39 | public DebuggerStmt( |
40 | FilePosition pos, Void value, List<? extends ParseTreeNode> children) { |
41 | super(pos, NoChildren.class); |
42 | } |
43 | |
44 | public DebuggerStmt(FilePosition pos) { super(pos, NoChildren.class); } |
45 | |
46 | @Override |
47 | public Object getValue() { return null; } |
48 | |
49 | public void render(RenderContext rc) { |
50 | TokenConsumer out = rc.getOut(); |
51 | out.mark(getFilePosition()); |
52 | out.consume("debugger"); |
53 | } |
54 | |
55 | public boolean hasHangingConditional() { return false; } |
56 | |
57 | public JsonML toJsonML() { |
58 | return JsonMLBuilder.builder(TagType.DebuggerStmt, getFilePosition()) |
59 | .build(); |
60 | } |
61 | } |