From 58bfc52a8ef7ba1129ac327009215a4e84da3b52 Mon Sep 17 00:00:00 2001
From: Adam Welc <adam.welc@oracle.com>
Date: Thu, 21 Jul 2016 18:33:30 +0200
Subject: [PATCH] Moved a flag determining browser mode to context.

---
 .../oracle/truffle/r/nodes/builtin/base/Quit.java  |  2 +-
 .../nodes/builtin/helpers/BrowserInteractNode.java | 14 ++------------
 .../oracle/truffle/r/runtime/context/RContext.java | 13 +++++++++++++
 3 files changed, 16 insertions(+), 13 deletions(-)

diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Quit.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Quit.java
index ce221bec41..764ce8d805 100644
--- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Quit.java
+++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Quit.java
@@ -52,7 +52,7 @@ public abstract class Quit extends RBuiltinNode {
     @Specialization
     @TruffleBoundary
     protected Object doQuit(RAbstractStringVector saveArg, final int status, final byte runLastIn) {
-        if (BrowserInteractNode.inBrowser()) {
+        if (RContext.getInstance().isInBrowser()) {
             RError.warning(this, RError.Message.BROWSER_QUIT);
             return RNull.instance;
         }
diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/helpers/BrowserInteractNode.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/helpers/BrowserInteractNode.java
index 0376ce1a06..38452e83e0 100644
--- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/helpers/BrowserInteractNode.java
+++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/helpers/BrowserInteractNode.java
@@ -61,16 +61,6 @@ public abstract class BrowserInteractNode extends RNode {
     private static final String BROWSER_SOURCE = "<browser_input>";
     private static String lastEmptyLineCommand = "n";
 
-    /**
-     * This used by {@link Quit} to prevent a "quit" from the browser (as per GnuR). If we supported
-     * multiple interactive contexts, this would need become context specific.
-     */
-    private static boolean inBrowser;
-
-    public static boolean inBrowser() {
-        return inBrowser;
-    }
-
     @Specialization
     protected int interact(VirtualFrame frame) {
         CompilerDirectives.transferToInterpreter();
@@ -80,7 +70,7 @@ public abstract class BrowserInteractNode extends RNode {
         ch.setPrompt(browserPrompt(RArguments.getDepth(frame)));
         int exitMode = NEXT;
         try {
-            inBrowser = true;
+            RContext.getInstance().setInBrowser(true);
             LW: while (true) {
                 String input = ch.readLine();
                 if (input != null) {
@@ -141,7 +131,7 @@ public abstract class BrowserInteractNode extends RNode {
             }
         } finally {
             ch.setPrompt(savedPrompt);
-            inBrowser = false;
+            RContext.getInstance().setInBrowser(false);
         }
         return exitMode;
     }
diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/context/RContext.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/context/RContext.java
index 5d7f114ca4..fd38892ac1 100644
--- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/context/RContext.java
+++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/context/RContext.java
@@ -292,6 +292,11 @@ public final class RContext extends ExecutionContext implements TruffleObject {
 
     private boolean nullS4Object = false;
 
+    /**
+     * This used to prevent a "quit" from the browser (as per GnuR).
+     */
+    private boolean inBrowser = false;
+
     private boolean active;
 
     private PrimitiveMethodsInfo primitiveMethodsInfo;
@@ -617,6 +622,14 @@ public final class RContext extends ExecutionContext implements TruffleObject {
         nullS4Object = on;
     }
 
+    public boolean isInBrowser() {
+        return inBrowser;
+    }
+
+    public void setInBrowser(boolean on) {
+        inBrowser = on;
+    }
+
     public boolean allowPrimitiveMethods() {
         return allowPrimitiveMethods;
     }
-- 
GitLab