Web Inspector: Eliminate the crazy code for evaluateOnCallFrame
https://bugs.webkit.org/show_bug.cgi?id=157510
<rdar://problem/26191332>

Reviewed by Timothy Hatcher.

Source/JavaScriptCore:

* debugger/DebuggerCallFrame.cpp:
(JSC::DebuggerCallFrame::evaluateWithScopeExtension):
Set and clear an optional scope extension object.

* inspector/InjectedScriptSource.js:
(InjectedScript.prototype.evaluate):
(InjectedScript.prototype._evaluateOn):
(InjectedScript.prototype.evaluateOnCallFrame):
Unify the code to use the passed in evaluate function and object.
When evaluating on a call frame the evaluate function ends up being
DebuggerCallFrame::evaluateWithScopeExtension. When evaluating globally
this ends up being JSInjectedScriptHost::evaluateWithScopeExtension.
In both cases "object" is the preferred this object to use.

* debugger/DebuggerCallFrame.h:
* inspector/JSJavaScriptCallFrame.cpp:
(Inspector::JSJavaScriptCallFrame::evaluateWithScopeExtension):
(Inspector::JSJavaScriptCallFrame::evaluate): Deleted.
* inspector/JSJavaScriptCallFrame.h:
* inspector/JSJavaScriptCallFramePrototype.cpp:
(Inspector::JSJavaScriptCallFramePrototype::finishCreation):
(Inspector::jsJavaScriptCallFramePrototypeFunctionEvaluateWithScopeExtension):
* inspector/JavaScriptCallFrame.h:
(Inspector::JavaScriptCallFrame::evaluateWithScopeExtension):
(Inspector::JavaScriptCallFrame::evaluate): Deleted.
Pass through to DebuggerCallFrame with the proper arguments.

* debugger/Debugger.cpp:
(JSC::Debugger::hasBreakpoint):
* inspector/ScriptDebugServer.cpp:
(Inspector::ScriptDebugServer::evaluateBreakpointAction):
Use the new evaluate on call frame method name and no scope extension object.

LayoutTests:

* inspector/debugger/evaluateOnCallFrame-CommandLineAPI-expected.txt: Added.
* inspector/debugger/evaluateOnCallFrame-CommandLineAPI.html: Added.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@200634 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/JavaScriptCore/debugger/DebuggerCallFrame.cpp b/Source/JavaScriptCore/debugger/DebuggerCallFrame.cpp
index 9277b59..4b34bf3 100644
--- a/Source/JavaScriptCore/debugger/DebuggerCallFrame.cpp
+++ b/Source/JavaScriptCore/debugger/DebuggerCallFrame.cpp
@@ -33,9 +33,10 @@
 #include "DebuggerEvalEnabler.h"
 #include "DebuggerScope.h"
 #include "Interpreter.h"
+#include "JSCInlines.h"
 #include "JSFunction.h"
 #include "JSLexicalEnvironment.h"
-#include "JSCInlines.h"
+#include "JSWithScope.h"
 #include "Parser.h"
 #include "StackVisitor.h"
 #include "StrongInlines.h"
@@ -175,17 +176,17 @@
 }
 
 // Evaluate some JavaScript code in the scope of this frame.
-JSValue DebuggerCallFrame::evaluate(const String& script, NakedPtr<Exception>& exception)
+JSValue DebuggerCallFrame::evaluateWithScopeExtension(const String& script, JSObject* scopeExtensionObject, NakedPtr<Exception>& exception)
 {
     ASSERT(isValid());
     CallFrame* callFrame = m_callFrame;
     if (!callFrame)
-        return jsNull();
+        return jsUndefined();
 
     JSLockHolder lock(callFrame);
 
     if (!callFrame->codeBlock())
-        return JSValue();
+        return jsUndefined();
     
     DebuggerEvalEnabler evalEnabler(callFrame);
     VM& vm = callFrame->vm();
@@ -211,12 +212,22 @@
         return jsUndefined();
     }
 
+    JSGlobalObject* globalObject = callFrame->vmEntryGlobalObject();
+    if (scopeExtensionObject) {
+        JSScope* ignoredPreviousScope = globalObject->globalScope();
+        globalObject->setGlobalScopeExtension(JSWithScope::create(vm, globalObject, scopeExtensionObject, ignoredPreviousScope));
+    }
+
     JSValue thisValue = thisValueForCallFrame(callFrame);
     JSValue result = vm.interpreter->execute(eval, callFrame, thisValue, scope()->jsScope());
     if (vm.exception()) {
         exception = vm.exception();
         vm.clearException();
     }
+
+    if (scopeExtensionObject)
+        globalObject->clearGlobalScopeExtension();
+
     ASSERT(result);
     return result;
 }