|
2 | 2 | # License: New BSD License. |
3 | 3 | # Website: http://code.google.com/p/cefpython/ |
4 | 4 |
|
5 | | -# CefV8 Objects, Arrays and Functions can be created only inside V8 context, |
6 | | -# you need to call CefV8Context::Enter() and CefV8Context::Exit(): |
| 5 | +# CefV8 Objects, Arrays and Functions can be created or modified only |
| 6 | +# inside V8 context, you need to call CefV8Context::Enter() and |
| 7 | +# CefV8Context::Exit(), see: |
7 | 8 | # http://code.google.com/p/chromiumembedded/issues/detail?id=203 |
8 | | -# Entering context should be done for Frame::CallFunction(). |
9 | | - |
10 | | -# Arrays, objects and functions may only be created, modified and, |
11 | | -# in the case of functions, executed, if V8 is inside a context. |
12 | | - |
13 | | -IF CEF_VERSION == 1: |
14 | | - |
15 | | - cdef list CefV8StackTraceToPython(CefRefPtr[CefV8StackTrace] cefTrace): |
16 | | - cdef int frameNumber |
17 | | - cdef int frameCount = cefTrace.get().GetFrameCount() |
18 | | - cdef CefRefPtr[CefV8StackFrame] cefFrame |
19 | | - cdef CefV8StackFrame* framePtr |
20 | | - cdef list pyTrace = [] |
21 | | - |
22 | | - for frameNumber in range(0, frameCount): |
23 | | - cefFrame = cefTrace.get().GetFrame(frameNumber) |
24 | | - framePtr = cefFrame.get() |
25 | | - pyFrame = {} |
26 | | - pyFrame["script"] = CefToPyString(framePtr.GetScriptName()) |
27 | | - pyFrame["scriptOrSourceUrl"] = CefToPyString( |
28 | | - framePtr.GetScriptNameOrSourceURL()) |
29 | | - pyFrame["function"] = CefToPyString(framePtr.GetFunctionName()) |
30 | | - pyFrame["line"] = framePtr.GetLineNumber() |
31 | | - pyFrame["column"] = framePtr.GetColumn() |
32 | | - pyFrame["isEval"] = framePtr.IsEval() |
33 | | - pyFrame["isConstructor"] = framePtr.IsConstructor() |
34 | | - pyTrace.append(pyFrame) |
35 | | - |
36 | | - return pyTrace |
37 | | - |
38 | | - cpdef list GetJavascriptStackTrace(int frameLimit=100): |
39 | | - assert IsThread(TID_UI), ( |
40 | | - "cefpython.GetJavascriptStackTrace() may only be called on the UI thread") |
41 | | - cdef CefRefPtr[CefV8StackTrace] cefTrace = ( |
42 | | - cef_v8_stack_trace.GetCurrent(frameLimit)) |
43 | | - return CefV8StackTraceToPython(cefTrace) |
44 | | - |
45 | | - cpdef str FormatJavascriptStackTrace(list stackTrace): |
46 | | - cdef str formatted = "" |
47 | | - cdef dict frame |
48 | | - for frameNumber, frame in enumerate(stackTrace): |
49 | | - formatted += "\t[%s] %s() in %s on line %s (col:%s)\n" % ( |
50 | | - frameNumber, |
51 | | - frame["function"], |
52 | | - frame["scriptOrSourceUrl"], |
53 | | - frame["line"], |
54 | | - frame["column"]) |
55 | | - return formatted |
| 9 | + |
| 10 | +cdef list CefV8StackTraceToPython(CefRefPtr[CefV8StackTrace] cefTrace): |
| 11 | + cdef int frameNumber |
| 12 | + cdef int frameCount = cefTrace.get().GetFrameCount() |
| 13 | + cdef CefRefPtr[CefV8StackFrame] cefFrame |
| 14 | + cdef CefV8StackFrame* framePtr |
| 15 | + cdef list pyTrace = [] |
| 16 | + |
| 17 | + for frameNumber in range(0, frameCount): |
| 18 | + cefFrame = cefTrace.get().GetFrame(frameNumber) |
| 19 | + framePtr = cefFrame.get() |
| 20 | + pyFrame = {} |
| 21 | + pyFrame["script"] = CefToPyString(framePtr.GetScriptName()) |
| 22 | + pyFrame["scriptOrSourceUrl"] = CefToPyString( |
| 23 | + framePtr.GetScriptNameOrSourceURL()) |
| 24 | + pyFrame["function"] = CefToPyString(framePtr.GetFunctionName()) |
| 25 | + pyFrame["line"] = framePtr.GetLineNumber() |
| 26 | + pyFrame["column"] = framePtr.GetColumn() |
| 27 | + pyFrame["isEval"] = framePtr.IsEval() |
| 28 | + pyFrame["isConstructor"] = framePtr.IsConstructor() |
| 29 | + pyTrace.append(pyFrame) |
| 30 | + |
| 31 | + return pyTrace |
| 32 | + |
| 33 | +cpdef list GetJavascriptStackTrace(int frameLimit=100): |
| 34 | + assert IsThread(TID_UI), ( |
| 35 | + "cefpython.GetJavascriptStackTrace() may only be called on the UI thread") |
| 36 | + cdef CefRefPtr[CefV8StackTrace] cefTrace = ( |
| 37 | + cef_v8_stack_trace.GetCurrent(frameLimit)) |
| 38 | + return CefV8StackTraceToPython(cefTrace) |
| 39 | + |
| 40 | +cpdef str FormatJavascriptStackTrace(list stackTrace): |
| 41 | + cdef str formatted = "" |
| 42 | + cdef dict frame |
| 43 | + for frameNumber, frame in enumerate(stackTrace): |
| 44 | + formatted += "\t[%s] %s() in %s on line %s (col:%s)\n" % ( |
| 45 | + frameNumber, |
| 46 | + frame["function"], |
| 47 | + frame["scriptOrSourceUrl"], |
| 48 | + frame["line"], |
| 49 | + frame["column"]) |
| 50 | + return formatted |
56 | 51 |
|
57 | 52 | cdef object V8ToPyValue( |
58 | 53 | CefRefPtr[CefV8Value] v8Value, |
|
0 commit comments