Title: [149202] trunk/Source
Revision
149202
Author
[email protected]
Date
2013-04-26 12:08:33 -0700 (Fri, 26 Apr 2013)

Log Message

Add Runtime.parse to the Inspector protocol.

This will be used to parse console expressions for errors
before evaluating them fully.

https://webkit.org/b/115242

Reviewed by Oliver Hunt.

* ForwardingHeaders/parser/ParserError.h: Added.
* inspector/Inspector.json:
* inspector/InspectorRuntimeAgent.cpp:
(WebCore::InspectorRuntimeAgent::parse):
* inspector/InspectorRuntimeAgent.h:
(InspectorRuntimeAgent):

Modified Paths

Added Paths

Diff

Modified: trunk/Source/_javascript_Core/_javascript_Core.vcproj/_javascript_Core/_javascript_CoreExports.def (149201 => 149202)


--- trunk/Source/_javascript_Core/_javascript_Core.vcproj/_javascript_Core/_javascript_CoreExports.def	2013-04-26 19:04:58 UTC (rev 149201)
+++ trunk/Source/_javascript_Core/_javascript_Core.vcproj/_javascript_Core/_javascript_CoreExports.def	2013-04-26 19:08:33 UTC (rev 149202)
@@ -142,6 +142,7 @@
     ?charactersToUIntStrict@WTF@@YAIPB_WIPA_NH@Z
     ?charactersWithNullTermination@String@WTF@@QAEPB_WXZ
     ?checkCurrentIdentifierTable@Identifier@JSC@@CAXPAVExecState@2@@Z
+    ?checkSyntax@JSC@@YA_NAAVVM@1@ABVSourceCode@1@AAUParserError@1@@Z
     ?checkSyntax@JSC@@YA_NPAVExecState@1@ABVSourceCode@1@PAVJSValue@1@@Z
     ?checksum@MD5@WTF@@QAEXAAV?$Vector@E$0BA@VCrashOnOverflow@WTF@@@2@@Z
     ?className@JSObject@JSC@@SA?AVString@WTF@@PBV12@@Z

Modified: trunk/Source/_javascript_Core/_javascript_Core.vcxproj/_javascript_CoreExportGenerator/_javascript_CoreExports.def.in (149201 => 149202)


--- trunk/Source/_javascript_Core/_javascript_Core.vcxproj/_javascript_CoreExportGenerator/_javascript_CoreExports.def.in	2013-04-26 19:04:58 UTC (rev 149201)
+++ trunk/Source/_javascript_Core/_javascript_Core.vcxproj/_javascript_CoreExportGenerator/_javascript_CoreExports.def.in	2013-04-26 19:08:33 UTC (rev 149202)
@@ -141,6 +141,7 @@
     ?charactersToUIntStrict@WTF@@YAIPB_WIPA_NH@Z
     ?charactersWithNullTermination@String@WTF@@QAEPB_WXZ
     ?checkCurrentIdentifierTable@Identifier@JSC@@CAXPAVExecState@2@@Z
+    ?checkSyntax@JSC@@YA_NAAVVM@1@ABVSourceCode@1@AAUParserError@1@@Z
     ?checkSyntax@JSC@@YA_NPAVExecState@1@ABVSourceCode@1@PAVJSValue@1@@Z
     ?checksum@MD5@WTF@@QAEXAAV?$Vector@E$0BA@VCrashOnOverflow@WTF@@@2@@Z
     ?className@JSObject@JSC@@SA?AVString@WTF@@PBV12@@Z

Modified: trunk/Source/WebCore/ChangeLog (149201 => 149202)


--- trunk/Source/WebCore/ChangeLog	2013-04-26 19:04:58 UTC (rev 149201)
+++ trunk/Source/WebCore/ChangeLog	2013-04-26 19:08:33 UTC (rev 149202)
@@ -1,3 +1,21 @@
+2013-04-26  Timothy Hatcher  <[email protected]>
+
+        Add Runtime.parse to the Inspector protocol.
+
+        This will be used to parse console expressions for errors
+        before evaluating them fully.
+
+        https://webkit.org/b/115242
+
+        Reviewed by Oliver Hunt.
+
+        * ForwardingHeaders/parser/ParserError.h: Added.
+        * inspector/Inspector.json:
+        * inspector/InspectorRuntimeAgent.cpp:
+        (WebCore::InspectorRuntimeAgent::parse):
+        * inspector/InspectorRuntimeAgent.h:
+        (InspectorRuntimeAgent):
+
 2013-04-26  Benjamin Poulain  <[email protected]>
 
         Fix the copyright years after r149057

Added: trunk/Source/WebCore/ForwardingHeaders/parser/ParserError.h (0 => 149202)


--- trunk/Source/WebCore/ForwardingHeaders/parser/ParserError.h	                        (rev 0)
+++ trunk/Source/WebCore/ForwardingHeaders/parser/ParserError.h	2013-04-26 19:08:33 UTC (rev 149202)
@@ -0,0 +1,4 @@
+#ifndef WebCore_FWD_ParserError_h
+#define WebCore_FWD_ParserError_h
+#include <_javascript_Core/ParserError.h>
+#endif

Modified: trunk/Source/WebCore/inspector/Inspector.json (149201 => 149202)


--- trunk/Source/WebCore/inspector/Inspector.json	2013-04-26 19:04:58 UTC (rev 149201)
+++ trunk/Source/WebCore/inspector/Inspector.json	2013-04-26 19:08:33 UTC (rev 149202)
@@ -663,11 +663,37 @@
                     { "name": "name", "type": "string", "description": "Human readable name describing given context.", "hidden": true},
                     { "name": "frameId", "$ref": "Network.FrameId", "description": "Id of the owning frame." }
                 ]
+            },
+            {
+                "id": "SyntaxErrorType",
+                "type": "string",
+                "enum": ["none", "irrecoverable", "unterminated-literal", "recoverable"],
+                "description": "Syntax error type: \"none\" for no error, \"irrecoverable\" for unrecoverable errors, \"unterminated-literal\" for when there is an unterminated literal, \"recoverable\" for when the _expression_ is unfinished but valid so far."
+            },
+            {
+                "id": "ErrorRange",
+                "type": "object",
+                "description": "Range of an error in source code.",
+                "properties": [
+                    { "name": "startOffset", "type": "integer", "description": "Start offset of range (inclusive)." },
+                    { "name": "endOffset", "type": "integer", "description": "End offset of range (exclusive)." }
+                ]
             }
-
         ],
         "commands": [
             {
+                "name": "parse",
+                "parameters": [
+                    { "name": "source", "type": "string", "description": "Source code to parse." }
+                ],
+                "returns": [
+                    { "name": "result", "$ref": "SyntaxErrorType", "description": "Parse result." },
+                    { "name": "message", "type": "string", "optional": true, "description": "Parse error message." },
+                    { "name": "range", "$ref": "ErrorRange", "optional": true, "description": "Range in the source where the error occurred." }
+                ],
+                "description": "Parses _javascript_ source code for errors."
+            },
+            {
                 "name": "evaluate",
                 "parameters": [
                     { "name": "_expression_", "type": "string", "description": "_expression_ to evaluate." },

Modified: trunk/Source/WebCore/inspector/InspectorRuntimeAgent.cpp (149201 => 149202)


--- trunk/Source/WebCore/inspector/InspectorRuntimeAgent.cpp	2013-04-26 19:04:58 UTC (rev 149201)
+++ trunk/Source/WebCore/inspector/InspectorRuntimeAgent.cpp	2013-04-26 19:08:33 UTC (rev 149202)
@@ -37,13 +37,19 @@
 #include "InjectedScript.h"
 #include "InjectedScriptManager.h"
 #include "InspectorValues.h"
+#include "JSDOMWindowBase.h"
+#include <parser/ParserError.h>
+#include <parser/SourceCode.h>
+#include <runtime/Completion.h>
+#include <runtime/JSLock.h>
 #include <wtf/PassRefPtr.h>
 
-
 #if ENABLE(_javascript__DEBUGGER)
 #include "ScriptDebugServer.h"
 #endif
 
+using namespace JSC;
+
 namespace WebCore {
 
 static bool asBool(const bool* const b)
@@ -76,6 +82,43 @@
 }
 #endif
 
+static PassRefPtr<TypeBuilder::Runtime::ErrorRange> buildErrorRangeObject(const JSTokenLocation& tokenLocation)
+{
+    RefPtr<TypeBuilder::Runtime::ErrorRange> result = TypeBuilder::Runtime::ErrorRange::create()
+        .setStartOffset(tokenLocation.startOffset)
+        .setEndOffset(tokenLocation.endOffset);
+    return result.release();
+}
+
+void InspectorRuntimeAgent::parse(ErrorString*, const String& _expression_, TypeBuilder::Runtime::SyntaxErrorType::Enum* result, TypeBuilder::OptOutput<String>* message, RefPtr<TypeBuilder::Runtime::ErrorRange>& range)
+{
+    VM* vm = JSDOMWindowBase::commonVM();
+    JSLockHolder lock(vm);
+
+    ParserError error;
+    checkSyntax(*vm, JSC::makeSource(_expression_), error);
+
+    switch (error.m_syntaxErrorType) {
+    case ParserError::SyntaxErrorNone:
+        *result = TypeBuilder::Runtime::SyntaxErrorType::None;
+        break;
+    case ParserError::SyntaxErrorIrrecoverable:
+        *result = TypeBuilder::Runtime::SyntaxErrorType::Irrecoverable;
+        break;
+    case ParserError::SyntaxErrorUnterminatedLiteral:
+        *result = TypeBuilder::Runtime::SyntaxErrorType::Unterminated_literal;
+        break;
+    case ParserError::SyntaxErrorRecoverable:
+        *result = TypeBuilder::Runtime::SyntaxErrorType::Recoverable;
+        break;
+    }
+
+    if (error.m_syntaxErrorType != ParserError::SyntaxErrorNone) {
+        *message = error.m_message;
+        range = buildErrorRangeObject(error.m_token.m_location);
+    }
+}
+
 void InspectorRuntimeAgent::evaluate(ErrorString* errorString, const String& _expression_, const String* const objectGroup, const bool* const includeCommandLineAPI, const bool* const doNotPauseOnExceptionsAndMuteConsole, const int* executionContextId, const bool* const returnByValue, const bool* generatePreview, RefPtr<TypeBuilder::Runtime::RemoteObject>& result, TypeBuilder::OptOutput<bool>* wasThrown)
 {
     InjectedScript injectedScript = injectedScriptForEval(errorString, executionContextId);

Modified: trunk/Source/WebCore/inspector/InspectorRuntimeAgent.h (149201 => 149202)


--- trunk/Source/WebCore/inspector/InspectorRuntimeAgent.h	2013-04-26 19:04:58 UTC (rev 149201)
+++ trunk/Source/WebCore/inspector/InspectorRuntimeAgent.h	2013-04-26 19:08:33 UTC (rev 149202)
@@ -61,6 +61,7 @@
     // Part of the protocol.
     virtual void enable(ErrorString*) { m_enabled = true; }
     virtual void disable(ErrorString*) { m_enabled = false; }
+    virtual void parse(ErrorString*, const String& _expression_, TypeBuilder::Runtime::SyntaxErrorType::Enum* result, TypeBuilder::OptOutput<String>* message, RefPtr<TypeBuilder::Runtime::ErrorRange>&);
     virtual void evaluate(ErrorString*,
                   const String& _expression_,
                   const String* objectGroup,
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to