OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 static v8::Local<v8::FunctionTemplate> libraryProxyTemplate(); | 51 static v8::Local<v8::FunctionTemplate> libraryProxyTemplate(); |
52 static v8::Local<v8::FunctionTemplate> typeProxyTemplate(Dart_Handle type); | 52 static v8::Local<v8::FunctionTemplate> typeProxyTemplate(Dart_Handle type); |
53 static v8::Local<v8::FunctionTemplate> frameProxyTemplate(); | 53 static v8::Local<v8::FunctionTemplate> frameProxyTemplate(); |
54 | 54 |
55 DartScriptValue* readPointerFromProxy(v8::Handle<v8::Value> proxy) | 55 DartScriptValue* readPointerFromProxy(v8::Handle<v8::Value> proxy) |
56 { | 56 { |
57 void* pointer = proxy.As<v8::Object>()->GetAlignedPointerFromInternalField(0
); | 57 void* pointer = proxy.As<v8::Object>()->GetAlignedPointerFromInternalField(0
); |
58 return static_cast<DartScriptValue*>(pointer); | 58 return static_cast<DartScriptValue*>(pointer); |
59 } | 59 } |
60 | 60 |
61 DartScopes::DartScopes(v8::Local<v8::Object> v8Handle) : | 61 DartScopes::DartScopes(v8::Local<v8::Object> v8Handle, bool disableBreak) : |
62 scriptValue(readPointerFromProxy(v8Handle)), | 62 scriptValue(readPointerFromProxy(v8Handle)), |
63 scope(scriptValue->isolate()) | 63 scope(scriptValue->isolate()), |
| 64 disableBreak(disableBreak) |
64 { | 65 { |
65 ASSERT(scriptValue->isIsolateAlive()); | 66 ASSERT(scriptValue->isIsolateAlive()); |
66 handle = scriptValue->value(); | 67 handle = scriptValue->value(); |
67 previousPauseInfo = Dart_GetExceptionPauseInfo(); | 68 if (disableBreak) { |
68 // FIXME: it is not clear this is the right long term solution but for | 69 previousPauseInfo = Dart_GetExceptionPauseInfo(); |
69 // now we prevent pausing on exceptions when executing Dart code to | 70 Dart_SetExceptionPauseInfo(kNoPauseOnExceptions); |
70 // avoid crashing when handling an exception triggers an exception. | 71 } |
71 Dart_SetExceptionPauseInfo(kNoPauseOnExceptions); | |
72 } | 72 } |
73 | 73 |
74 DartScopes::~DartScopes() | 74 DartScopes::~DartScopes() |
75 { | 75 { |
76 Dart_SetExceptionPauseInfo(previousPauseInfo); | 76 if (disableBreak) { |
| 77 Dart_SetExceptionPauseInfo(previousPauseInfo); |
| 78 } |
77 } | 79 } |
78 | 80 |
79 | 81 |
80 static void weakCallback(v8::Isolate* isolate, v8::Persistent<v8::Object>* proxy
, DartScriptValue* value) | 82 static void weakCallback(v8::Isolate* isolate, v8::Persistent<v8::Object>* proxy
, DartScriptValue* value) |
81 { | 83 { |
82 delete value; | 84 delete value; |
83 proxy->Dispose(isolate); | 85 proxy->Dispose(isolate); |
84 } | 86 } |
85 | 87 |
86 Dart_Handle DartHandleProxy::unwrapValue(v8::Handle<v8::Value> value) | 88 Dart_Handle DartHandleProxy::unwrapValue(v8::Handle<v8::Value> value) |
(...skipping 991 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1078 v8::Handle<v8::Value> DartHandleProxy::createLocalScopeProxy(Dart_Handle localVa
riables) | 1080 v8::Handle<v8::Value> DartHandleProxy::createLocalScopeProxy(Dart_Handle localVa
riables) |
1079 { | 1081 { |
1080 v8::Local<v8::Object> proxy = frameProxyTemplate()->InstanceTemplate()->NewI
nstance(); | 1082 v8::Local<v8::Object> proxy = frameProxyTemplate()->InstanceTemplate()->NewI
nstance(); |
1081 Dart_Handle localScopeVariableMap = createLocalVariablesMap(localVariables); | 1083 Dart_Handle localScopeVariableMap = createLocalVariablesMap(localVariables); |
1082 ASSERT(!Dart_IsError(localScopeVariableMap)); | 1084 ASSERT(!Dart_IsError(localScopeVariableMap)); |
1083 setDartHandleInternalField(proxy, localScopeVariableMap); | 1085 setDartHandleInternalField(proxy, localScopeVariableMap); |
1084 proxy->SetHiddenValue(v8::String::NewSymbol("dartProxy"), v8::Boolean::New(t
rue)); | 1086 proxy->SetHiddenValue(v8::String::NewSymbol("dartProxy"), v8::Boolean::New(t
rue)); |
1085 return proxy; | 1087 return proxy; |
1086 } | 1088 } |
1087 | 1089 |
| 1090 v8::Handle<v8::Value> DartHandleProxy::evaluate(Dart_Handle target, Dart_Handle
expression, Dart_Handle localVariables) |
| 1091 { |
| 1092 ASSERT(Dart_IsList(localVariables) || Dart_IsNull(localVariables)); |
| 1093 intptr_t localVariablesLength = 0; |
| 1094 Dart_ListLength(localVariables, &localVariablesLength); |
| 1095 |
| 1096 Dart_Handle wrapExpressionArgs[2] = { expression, localVariables }; |
| 1097 Dart_Handle exception = 0; |
| 1098 bool ret = DartUtilities::dartToBool(DartUtilities::invokeUtilsMethod("isJsE
xpression", 1, &expression), exception); |
| 1099 ASSERT(!exception); |
| 1100 if (ret) { |
| 1101 // FIXME(dartbug.com/13468): remove this hacky fallback of invoking JS |
| 1102 // code when we believe a JS code fragment generated by the chrome |
| 1103 // developer tools was passed to us rather than a fragment of true |
| 1104 // Dart code. |
| 1105 ASSERT(!v8::Context::GetCurrent().IsEmpty()); |
| 1106 v8::Handle<v8::Value> result = V8ScriptRunner::compileAndRunInternalScri
pt(V8Converter::stringToV8(expression), v8::Isolate::GetCurrent()); |
| 1107 return result; |
| 1108 } |
| 1109 |
| 1110 Dart_Handle wrappedExpressionTuple = |
| 1111 DartUtilities::invokeUtilsMethod("wrapExpressionAsClosure", 2, wrapExpre
ssionArgs); |
| 1112 ASSERT(Dart_IsList(wrappedExpressionTuple)); |
| 1113 Dart_Handle wrappedExpression = Dart_ListGetAt(wrappedExpressionTuple, 0); |
| 1114 Dart_Handle wrappedExpressionArgs = Dart_ListGetAt(wrappedExpressionTuple, 1
); |
| 1115 |
| 1116 ASSERT(Dart_IsString(wrappedExpression)); |
| 1117 Dart_Handle closure = Dart_EvaluateExpr(target, wrappedExpression); |
| 1118 // There was a parse error. FIXME: consider cleaning up the line numbers in |
| 1119 // the error message. |
| 1120 if (Dart_IsError(closure)) |
| 1121 return V8ThrowException::throwError(v8::String::New(Dart_GetError(closur
e))); |
| 1122 |
| 1123 // Invoke the closure passing in the expression arguments specified by |
| 1124 // wrappedExpressionTuple. |
| 1125 ASSERT(Dart_IsClosure(closure)); |
| 1126 intptr_t length = 0; |
| 1127 Dart_ListLength(wrappedExpressionArgs, &length); |
| 1128 Vector<Dart_Handle> dartFunctionArgs; |
| 1129 for (uint32_t i = 0; i < length; i ++) |
| 1130 dartFunctionArgs.append(Dart_ListGetAt(wrappedExpressionArgs, i)); |
| 1131 |
| 1132 Dart_Handle result = Dart_InvokeClosure(closure, dartFunctionArgs.size(), da
rtFunctionArgs.data()); |
| 1133 if (Dart_IsError(result)) |
| 1134 return V8ThrowException::throwError(v8::String::New(Dart_GetError(result
))); |
| 1135 return DartHandleProxy::create(result); |
1088 } | 1136 } |
| 1137 |
| 1138 } |
OLD | NEW |