equal
deleted
inserted
replaced
1 |
|
2 package jdk.nashorn.internal.codegen; |
|
3 |
|
4 import java.lang.reflect.Field; |
|
5 import jdk.nashorn.internal.ir.FunctionNode; |
|
6 |
|
7 /** |
|
8 * Since Compiler class doesn't give us access to its private {@code functionNode} field, we use this reflection-based |
|
9 * access-check disabling helper to get to it in compilation tests. |
|
10 * |
|
11 */ |
|
12 public class CompilerAccess { |
|
13 private static final Field FUNCTION_NODE_FIELD = getCompilerFunctionNodeField(); |
|
14 static { |
|
15 FUNCTION_NODE_FIELD.setAccessible(true); |
|
16 } |
|
17 |
|
18 /** |
|
19 * Given a compiler, return its {@code functionNode} field, representing the root function (i.e. the compiled script). |
|
20 * @param compiler the compiler that already run its {@link Compiler#compile()} method. |
|
21 * @return the root function node representing the compiled script. |
|
22 * @throws IllegalAccessException |
|
23 */ |
|
24 public static FunctionNode getScriptNode(Compiler compiler) throws IllegalAccessException { |
|
25 return (FunctionNode)FUNCTION_NODE_FIELD.get(compiler); |
|
26 } |
|
27 |
|
28 private static Field getCompilerFunctionNodeField() { |
|
29 try { |
|
30 return Compiler.class.getDeclaredField("functionNode"); |
|
31 } catch (NoSuchFieldException e) { |
|
32 throw new AssertionError("", e); |
|
33 } |
|
34 } |
|
35 } |
|