OLD | NEW |
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 class EvaluateException(Exception): | 4 from telemetry.core import exceptions |
5 pass | |
6 | 5 |
7 class InspectorRuntime(object): | 6 class InspectorRuntime(object): |
8 def __init__(self, inspector_backend): | 7 def __init__(self, inspector_backend): |
9 self._inspector_backend = inspector_backend | 8 self._inspector_backend = inspector_backend |
10 self._inspector_backend.RegisterDomain( | 9 self._inspector_backend.RegisterDomain( |
11 'Runtime', | 10 'Runtime', |
12 self._OnNotification, | 11 self._OnNotification, |
13 self._OnClose) | 12 self._OnClose) |
14 | 13 |
15 def _OnNotification(self, msg): | 14 def _OnNotification(self, msg): |
(...skipping 23 matching lines...) Expand all Loading... |
39 """ | 38 """ |
40 request = { | 39 request = { |
41 'method': 'Runtime.evaluate', | 40 'method': 'Runtime.evaluate', |
42 'params': { | 41 'params': { |
43 'expression': expr, | 42 'expression': expr, |
44 'returnByValue': True | 43 'returnByValue': True |
45 } | 44 } |
46 } | 45 } |
47 res = self._inspector_backend.SyncRequest(request, timeout) | 46 res = self._inspector_backend.SyncRequest(request, timeout) |
48 if 'error' in res: | 47 if 'error' in res: |
49 raise EvaluateException(res['error']['message']) | 48 raise exceptions.EvaluateException(res['error']['message']) |
50 | 49 |
51 if 'wasThrown' in res['result'] and res['result']['wasThrown']: | 50 if 'wasThrown' in res['result'] and res['result']['wasThrown']: |
52 # TODO(nduca): propagate stacks from javascript up to the python | 51 # TODO(nduca): propagate stacks from javascript up to the python |
53 # exception. | 52 # exception. |
54 raise EvaluateException(res['result']['result']['description']) | 53 raise exceptions.EvaluateException(res['result']['result']['description']) |
55 if res['result']['result']['type'] == 'undefined': | 54 if res['result']['result']['type'] == 'undefined': |
56 return None | 55 return None |
57 return res['result']['result']['value'] | 56 return res['result']['result']['value'] |
OLD | NEW |