kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1 | // Copyright 2011 the V8 project authors. All rights reserved. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2 | // Redistribution and use in source and binary forms, with or without |
| 3 | // modification, are permitted provided that the following conditions are |
| 4 | // met: |
| 5 | // |
| 6 | // * Redistributions of source code must retain the above copyright |
| 7 | // notice, this list of conditions and the following disclaimer. |
| 8 | // * Redistributions in binary form must reproduce the above |
| 9 | // copyright notice, this list of conditions and the following |
| 10 | // disclaimer in the documentation and/or other materials provided |
| 11 | // with the distribution. |
| 12 | // * Neither the name of Google Inc. nor the names of its |
| 13 | // contributors may be used to endorse or promote products derived |
| 14 | // from this software without specific prior written permission. |
| 15 | // |
| 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | |
| 28 | #include <stdlib.h> |
| 29 | |
| 30 | #include "v8.h" |
| 31 | |
| 32 | #include "api.h" |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 33 | #include "bootstrapper.h" |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 34 | #include "codegen.h" |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 35 | #include "debug.h" |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 36 | #include "isolate-inl.h" |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 37 | #include "runtime-profiler.h" |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 38 | #include "simulator.h" |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 39 | #include "v8threads.h" |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 40 | #include "vm-state-inl.h" |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 41 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 42 | namespace v8 { |
| 43 | namespace internal { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 44 | |
| 45 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 46 | StackGuard::StackGuard() |
| 47 | : isolate_(NULL) { |
| 48 | } |
| 49 | |
| 50 | |
| 51 | void StackGuard::set_interrupt_limits(const ExecutionAccess& lock) { |
| 52 | ASSERT(isolate_ != NULL); |
| 53 | // Ignore attempts to interrupt when interrupts are postponed. |
| 54 | if (should_postpone_interrupts(lock)) return; |
| 55 | thread_local_.jslimit_ = kInterruptLimit; |
| 56 | thread_local_.climit_ = kInterruptLimit; |
| 57 | isolate_->heap()->SetStackLimits(); |
| 58 | } |
| 59 | |
| 60 | |
| 61 | void StackGuard::reset_limits(const ExecutionAccess& lock) { |
| 62 | ASSERT(isolate_ != NULL); |
| 63 | thread_local_.jslimit_ = thread_local_.real_jslimit_; |
| 64 | thread_local_.climit_ = thread_local_.real_climit_; |
| 65 | isolate_->heap()->SetStackLimits(); |
| 66 | } |
| 67 | |
| 68 | |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 69 | static Handle<Object> Invoke(bool is_construct, |
| 70 | Handle<JSFunction> function, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 71 | Handle<Object> receiver, |
| 72 | int argc, |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 73 | Handle<Object> args[], |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 74 | bool* has_pending_exception) { |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 75 | Isolate* isolate = function->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 76 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 77 | // Entering JavaScript. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 78 | VMState state(isolate, JS); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 79 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 80 | // Placeholder for return value. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 81 | MaybeObject* value = reinterpret_cast<Object*>(kZapValue); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 82 | |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 83 | typedef Object* (*JSEntryFunction)(byte* entry, |
| 84 | Object* function, |
| 85 | Object* receiver, |
| 86 | int argc, |
| 87 | Object*** args); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 88 | |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 89 | Handle<Code> code = is_construct |
| 90 | ? isolate->factory()->js_construct_entry_code() |
| 91 | : isolate->factory()->js_entry_code(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 92 | |
sgjesse@chromium.org | 8d96e6d | 2009-08-07 10:18:15 +0000 | [diff] [blame] | 93 | // Convert calls on global objects to be calls on the global |
| 94 | // receiver instead to avoid having a 'this' pointer which refers |
| 95 | // directly to a global object. |
| 96 | if (receiver->IsGlobalObject()) { |
| 97 | Handle<GlobalObject> global = Handle<GlobalObject>::cast(receiver); |
| 98 | receiver = Handle<JSObject>(global->global_receiver()); |
| 99 | } |
| 100 | |
kasperl@chromium.org | 7b9eafd | 2009-12-21 15:20:30 +0000 | [diff] [blame] | 101 | // Make sure that the global object of the context we're about to |
| 102 | // make the current one is indeed a global object. |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 103 | ASSERT(function->context()->global()->IsGlobalObject()); |
kasperl@chromium.org | 7b9eafd | 2009-12-21 15:20:30 +0000 | [diff] [blame] | 104 | |
kasper.lund | 4451067 | 2008-07-25 07:37:58 +0000 | [diff] [blame] | 105 | { |
| 106 | // Save and restore context around invocation and block the |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 107 | // allocation of handles without explicit handle scopes. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 108 | SaveContext save(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 109 | NoHandleAllocation na; |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 110 | JSEntryFunction stub_entry = FUNCTION_CAST<JSEntryFunction>(code->entry()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 111 | |
| 112 | // Call the function through the right JS entry stub. |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 113 | byte* function_entry = function->code()->entry(); |
| 114 | JSFunction* func = *function; |
| 115 | Object* recv = *receiver; |
| 116 | Object*** argv = reinterpret_cast<Object***>(args); |
| 117 | value = |
| 118 | CALL_GENERATED_CODE(stub_entry, function_entry, func, recv, argc, argv); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | #ifdef DEBUG |
| 122 | value->Verify(); |
| 123 | #endif |
| 124 | |
| 125 | // Update the pending exception flag and return the value. |
| 126 | *has_pending_exception = value->IsException(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 127 | ASSERT(*has_pending_exception == Isolate::Current()->has_pending_exception()); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 128 | if (*has_pending_exception) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 129 | isolate->ReportPendingMessages(); |
| 130 | if (isolate->pending_exception() == Failure::OutOfMemoryException()) { |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 131 | if (!isolate->ignore_out_of_memory()) { |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 132 | V8::FatalProcessOutOfMemory("JS", true); |
| 133 | } |
| 134 | } |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 135 | return Handle<Object>(); |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 136 | } else { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 137 | isolate->clear_pending_message(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 138 | } |
| 139 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 140 | return Handle<Object>(value->ToObjectUnchecked(), isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 144 | Handle<Object> Execution::Call(Handle<Object> callable, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 145 | Handle<Object> receiver, |
| 146 | int argc, |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 147 | Handle<Object> argv[], |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 148 | bool* pending_exception, |
| 149 | bool convert_receiver) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 150 | *pending_exception = false; |
| 151 | |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 152 | if (!callable->IsJSFunction()) { |
| 153 | callable = TryGetFunctionDelegate(callable, pending_exception); |
| 154 | if (*pending_exception) return callable; |
| 155 | } |
| 156 | Handle<JSFunction> func = Handle<JSFunction>::cast(callable); |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 157 | |
| 158 | // In non-strict mode, convert receiver. |
| 159 | if (convert_receiver && !receiver->IsJSReceiver() && |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 160 | !func->shared()->native() && func->shared()->is_classic_mode()) { |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 161 | if (receiver->IsUndefined() || receiver->IsNull()) { |
| 162 | Object* global = func->context()->global()->global_receiver(); |
| 163 | // Under some circumstances, 'global' can be the JSBuiltinsObject |
| 164 | // In that case, don't rewrite. |
| 165 | // (FWIW, the same holds for GetIsolate()->global()->global_receiver().) |
| 166 | if (!global->IsJSBuiltinsObject()) receiver = Handle<Object>(global); |
| 167 | } else { |
| 168 | receiver = ToObject(receiver, pending_exception); |
| 169 | } |
| 170 | if (*pending_exception) return callable; |
| 171 | } |
| 172 | |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 173 | return Invoke(false, func, receiver, argc, argv, pending_exception); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 174 | } |
| 175 | |
| 176 | |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 177 | Handle<Object> Execution::New(Handle<JSFunction> func, |
| 178 | int argc, |
| 179 | Handle<Object> argv[], |
| 180 | bool* pending_exception) { |
| 181 | return Invoke(true, func, Isolate::Current()->global(), argc, argv, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 182 | pending_exception); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 183 | } |
| 184 | |
| 185 | |
| 186 | Handle<Object> Execution::TryCall(Handle<JSFunction> func, |
| 187 | Handle<Object> receiver, |
| 188 | int argc, |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 189 | Handle<Object> args[], |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 190 | bool* caught_exception) { |
| 191 | // Enter a try-block while executing the JavaScript code. To avoid |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 192 | // duplicate error printing it must be non-verbose. Also, to avoid |
| 193 | // creating message objects during stack overflow we shouldn't |
| 194 | // capture messages. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 195 | v8::TryCatch catcher; |
| 196 | catcher.SetVerbose(false); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 197 | catcher.SetCaptureMessage(false); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 198 | *caught_exception = false; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 199 | |
| 200 | Handle<Object> result = Invoke(false, func, receiver, argc, args, |
| 201 | caught_exception); |
| 202 | |
| 203 | if (*caught_exception) { |
| 204 | ASSERT(catcher.HasCaught()); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 205 | Isolate* isolate = Isolate::Current(); |
| 206 | ASSERT(isolate->has_pending_exception()); |
| 207 | ASSERT(isolate->external_caught_exception()); |
| 208 | if (isolate->pending_exception() == |
| 209 | isolate->heap()->termination_exception()) { |
| 210 | result = isolate->factory()->termination_exception(); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 211 | } else { |
| 212 | result = v8::Utils::OpenHandle(*catcher.Exception()); |
| 213 | } |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 214 | isolate->OptionalRescheduleException(true); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 215 | } |
| 216 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 217 | ASSERT(!Isolate::Current()->has_pending_exception()); |
| 218 | ASSERT(!Isolate::Current()->external_caught_exception()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 219 | return result; |
| 220 | } |
| 221 | |
| 222 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 223 | Handle<Object> Execution::GetFunctionDelegate(Handle<Object> object) { |
| 224 | ASSERT(!object->IsJSFunction()); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 225 | Isolate* isolate = Isolate::Current(); |
| 226 | Factory* factory = isolate->factory(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 227 | |
| 228 | // If you return a function from here, it will be called when an |
| 229 | // attempt is made to call the given object as a function. |
| 230 | |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 231 | // If object is a function proxy, get its handler. Iterate if necessary. |
| 232 | Object* fun = *object; |
| 233 | while (fun->IsJSFunctionProxy()) { |
| 234 | fun = JSFunctionProxy::cast(fun)->call_trap(); |
| 235 | } |
| 236 | if (fun->IsJSFunction()) return Handle<Object>(fun); |
| 237 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 238 | // Objects created through the API can have an instance-call handler |
| 239 | // that should be used when calling the object as a function. |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 240 | if (fun->IsHeapObject() && |
| 241 | HeapObject::cast(fun)->map()->has_instance_call_handler()) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 242 | return Handle<JSFunction>( |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 243 | isolate->global_context()->call_as_function_delegate()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 244 | } |
| 245 | |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 246 | return factory->undefined_value(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 247 | } |
| 248 | |
| 249 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 250 | Handle<Object> Execution::TryGetFunctionDelegate(Handle<Object> object, |
| 251 | bool* has_pending_exception) { |
| 252 | ASSERT(!object->IsJSFunction()); |
| 253 | Isolate* isolate = Isolate::Current(); |
| 254 | |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 255 | // If object is a function proxy, get its handler. Iterate if necessary. |
| 256 | Object* fun = *object; |
| 257 | while (fun->IsJSFunctionProxy()) { |
| 258 | fun = JSFunctionProxy::cast(fun)->call_trap(); |
| 259 | } |
| 260 | if (fun->IsJSFunction()) return Handle<Object>(fun); |
| 261 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 262 | // Objects created through the API can have an instance-call handler |
| 263 | // that should be used when calling the object as a function. |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 264 | if (fun->IsHeapObject() && |
| 265 | HeapObject::cast(fun)->map()->has_instance_call_handler()) { |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 266 | return Handle<JSFunction>( |
| 267 | isolate->global_context()->call_as_function_delegate()); |
| 268 | } |
| 269 | |
| 270 | // If the Object doesn't have an instance-call handler we should |
| 271 | // throw a non-callable exception. |
| 272 | i::Handle<i::Object> error_obj = isolate->factory()->NewTypeError( |
| 273 | "called_non_callable", i::HandleVector<i::Object>(&object, 1)); |
| 274 | isolate->Throw(*error_obj); |
| 275 | *has_pending_exception = true; |
| 276 | |
| 277 | return isolate->factory()->undefined_value(); |
| 278 | } |
| 279 | |
| 280 | |
sgjesse@chromium.org | 05521fc | 2009-05-21 07:37:44 +0000 | [diff] [blame] | 281 | Handle<Object> Execution::GetConstructorDelegate(Handle<Object> object) { |
| 282 | ASSERT(!object->IsJSFunction()); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 283 | Isolate* isolate = Isolate::Current(); |
sgjesse@chromium.org | 05521fc | 2009-05-21 07:37:44 +0000 | [diff] [blame] | 284 | |
| 285 | // If you return a function from here, it will be called when an |
| 286 | // attempt is made to call the given object as a constructor. |
| 287 | |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 288 | // If object is a function proxies, get its handler. Iterate if necessary. |
| 289 | Object* fun = *object; |
| 290 | while (fun->IsJSFunctionProxy()) { |
| 291 | fun = JSFunctionProxy::cast(fun)->call_trap(); |
| 292 | } |
| 293 | if (fun->IsJSFunction()) return Handle<Object>(fun); |
| 294 | |
sgjesse@chromium.org | 05521fc | 2009-05-21 07:37:44 +0000 | [diff] [blame] | 295 | // Objects created through the API can have an instance-call handler |
| 296 | // that should be used when calling the object as a function. |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 297 | if (fun->IsHeapObject() && |
| 298 | HeapObject::cast(fun)->map()->has_instance_call_handler()) { |
sgjesse@chromium.org | 05521fc | 2009-05-21 07:37:44 +0000 | [diff] [blame] | 299 | return Handle<JSFunction>( |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 300 | isolate->global_context()->call_as_constructor_delegate()); |
sgjesse@chromium.org | 05521fc | 2009-05-21 07:37:44 +0000 | [diff] [blame] | 301 | } |
| 302 | |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 303 | return isolate->factory()->undefined_value(); |
sgjesse@chromium.org | 05521fc | 2009-05-21 07:37:44 +0000 | [diff] [blame] | 304 | } |
| 305 | |
| 306 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 307 | Handle<Object> Execution::TryGetConstructorDelegate( |
| 308 | Handle<Object> object, |
| 309 | bool* has_pending_exception) { |
| 310 | ASSERT(!object->IsJSFunction()); |
| 311 | Isolate* isolate = Isolate::Current(); |
| 312 | |
| 313 | // If you return a function from here, it will be called when an |
| 314 | // attempt is made to call the given object as a constructor. |
| 315 | |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 316 | // If object is a function proxies, get its handler. Iterate if necessary. |
| 317 | Object* fun = *object; |
| 318 | while (fun->IsJSFunctionProxy()) { |
| 319 | fun = JSFunctionProxy::cast(fun)->call_trap(); |
| 320 | } |
| 321 | if (fun->IsJSFunction()) return Handle<Object>(fun); |
| 322 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 323 | // Objects created through the API can have an instance-call handler |
| 324 | // that should be used when calling the object as a function. |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 325 | if (fun->IsHeapObject() && |
| 326 | HeapObject::cast(fun)->map()->has_instance_call_handler()) { |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 327 | return Handle<JSFunction>( |
| 328 | isolate->global_context()->call_as_constructor_delegate()); |
| 329 | } |
| 330 | |
| 331 | // If the Object doesn't have an instance-call handler we should |
| 332 | // throw a non-callable exception. |
| 333 | i::Handle<i::Object> error_obj = isolate->factory()->NewTypeError( |
| 334 | "called_non_callable", i::HandleVector<i::Object>(&object, 1)); |
| 335 | isolate->Throw(*error_obj); |
| 336 | *has_pending_exception = true; |
| 337 | |
| 338 | return isolate->factory()->undefined_value(); |
| 339 | } |
| 340 | |
| 341 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 342 | bool StackGuard::IsStackOverflow() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 343 | ExecutionAccess access(isolate_); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 344 | return (thread_local_.jslimit_ != kInterruptLimit && |
| 345 | thread_local_.climit_ != kInterruptLimit); |
| 346 | } |
| 347 | |
| 348 | |
| 349 | void StackGuard::EnableInterrupts() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 350 | ExecutionAccess access(isolate_); |
whesse@chromium.org | b6e43bb | 2010-04-14 09:36:28 +0000 | [diff] [blame] | 351 | if (has_pending_interrupts(access)) { |
| 352 | set_interrupt_limits(access); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 353 | } |
| 354 | } |
| 355 | |
| 356 | |
| 357 | void StackGuard::SetStackLimit(uintptr_t limit) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 358 | ExecutionAccess access(isolate_); |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 359 | // If the current limits are special (e.g. due to a pending interrupt) then |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 360 | // leave them alone. |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 361 | uintptr_t jslimit = SimulatorStack::JsLimitFromCLimit(isolate_, limit); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 362 | if (thread_local_.jslimit_ == thread_local_.real_jslimit_) { |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 363 | thread_local_.jslimit_ = jslimit; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 364 | } |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 365 | if (thread_local_.climit_ == thread_local_.real_climit_) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 366 | thread_local_.climit_ = limit; |
| 367 | } |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 368 | thread_local_.real_climit_ = limit; |
| 369 | thread_local_.real_jslimit_ = jslimit; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 370 | } |
| 371 | |
| 372 | |
| 373 | void StackGuard::DisableInterrupts() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 374 | ExecutionAccess access(isolate_); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 375 | reset_limits(access); |
| 376 | } |
| 377 | |
| 378 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 379 | bool StackGuard::IsInterrupted() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 380 | ExecutionAccess access(isolate_); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 381 | return (thread_local_.interrupt_flags_ & INTERRUPT) != 0; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 382 | } |
| 383 | |
| 384 | |
| 385 | void StackGuard::Interrupt() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 386 | ExecutionAccess access(isolate_); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 387 | thread_local_.interrupt_flags_ |= INTERRUPT; |
whesse@chromium.org | b6e43bb | 2010-04-14 09:36:28 +0000 | [diff] [blame] | 388 | set_interrupt_limits(access); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 389 | } |
| 390 | |
| 391 | |
| 392 | bool StackGuard::IsPreempted() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 393 | ExecutionAccess access(isolate_); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 394 | return thread_local_.interrupt_flags_ & PREEMPT; |
| 395 | } |
| 396 | |
| 397 | |
| 398 | void StackGuard::Preempt() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 399 | ExecutionAccess access(isolate_); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 400 | thread_local_.interrupt_flags_ |= PREEMPT; |
whesse@chromium.org | b6e43bb | 2010-04-14 09:36:28 +0000 | [diff] [blame] | 401 | set_interrupt_limits(access); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 402 | } |
| 403 | |
| 404 | |
sgjesse@chromium.org | c81c894 | 2009-08-21 10:54:26 +0000 | [diff] [blame] | 405 | bool StackGuard::IsTerminateExecution() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 406 | ExecutionAccess access(isolate_); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 407 | return (thread_local_.interrupt_flags_ & TERMINATE) != 0; |
sgjesse@chromium.org | c81c894 | 2009-08-21 10:54:26 +0000 | [diff] [blame] | 408 | } |
| 409 | |
| 410 | |
| 411 | void StackGuard::TerminateExecution() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 412 | ExecutionAccess access(isolate_); |
sgjesse@chromium.org | c81c894 | 2009-08-21 10:54:26 +0000 | [diff] [blame] | 413 | thread_local_.interrupt_flags_ |= TERMINATE; |
whesse@chromium.org | b6e43bb | 2010-04-14 09:36:28 +0000 | [diff] [blame] | 414 | set_interrupt_limits(access); |
sgjesse@chromium.org | c81c894 | 2009-08-21 10:54:26 +0000 | [diff] [blame] | 415 | } |
| 416 | |
| 417 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 418 | bool StackGuard::IsRuntimeProfilerTick() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 419 | ExecutionAccess access(isolate_); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 420 | return (thread_local_.interrupt_flags_ & RUNTIME_PROFILER_TICK) != 0; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 421 | } |
| 422 | |
| 423 | |
| 424 | void StackGuard::RequestRuntimeProfilerTick() { |
| 425 | // Ignore calls if we're not optimizing or if we can't get the lock. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 426 | if (FLAG_opt && ExecutionAccess::TryLock(isolate_)) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 427 | thread_local_.interrupt_flags_ |= RUNTIME_PROFILER_TICK; |
| 428 | if (thread_local_.postpone_interrupts_nesting_ == 0) { |
| 429 | thread_local_.jslimit_ = thread_local_.climit_ = kInterruptLimit; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 430 | isolate_->heap()->SetStackLimits(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 431 | } |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 432 | ExecutionAccess::Unlock(isolate_); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 433 | } |
| 434 | } |
| 435 | |
| 436 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 437 | bool StackGuard::IsGCRequest() { |
| 438 | ExecutionAccess access(isolate_); |
| 439 | return (thread_local_.interrupt_flags_ & GC_REQUEST) != 0; |
| 440 | } |
| 441 | |
| 442 | |
| 443 | void StackGuard::RequestGC() { |
| 444 | ExecutionAccess access(isolate_); |
| 445 | thread_local_.interrupt_flags_ |= GC_REQUEST; |
| 446 | if (thread_local_.postpone_interrupts_nesting_ == 0) { |
| 447 | thread_local_.jslimit_ = thread_local_.climit_ = kInterruptLimit; |
| 448 | isolate_->heap()->SetStackLimits(); |
| 449 | } |
| 450 | } |
| 451 | |
| 452 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 453 | #ifdef ENABLE_DEBUGGER_SUPPORT |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 454 | bool StackGuard::IsDebugBreak() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 455 | ExecutionAccess access(isolate_); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 456 | return thread_local_.interrupt_flags_ & DEBUGBREAK; |
| 457 | } |
| 458 | |
kasper.lund | 4451067 | 2008-07-25 07:37:58 +0000 | [diff] [blame] | 459 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 460 | void StackGuard::DebugBreak() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 461 | ExecutionAccess access(isolate_); |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 462 | thread_local_.interrupt_flags_ |= DEBUGBREAK; |
whesse@chromium.org | b6e43bb | 2010-04-14 09:36:28 +0000 | [diff] [blame] | 463 | set_interrupt_limits(access); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 464 | } |
| 465 | |
| 466 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 467 | bool StackGuard::IsDebugCommand() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 468 | ExecutionAccess access(isolate_); |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 469 | return thread_local_.interrupt_flags_ & DEBUGCOMMAND; |
| 470 | } |
| 471 | |
| 472 | |
| 473 | void StackGuard::DebugCommand() { |
| 474 | if (FLAG_debugger_auto_break) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 475 | ExecutionAccess access(isolate_); |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 476 | thread_local_.interrupt_flags_ |= DEBUGCOMMAND; |
whesse@chromium.org | b6e43bb | 2010-04-14 09:36:28 +0000 | [diff] [blame] | 477 | set_interrupt_limits(access); |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 478 | } |
| 479 | } |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 480 | #endif |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 481 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 482 | void StackGuard::Continue(InterruptFlag after_what) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 483 | ExecutionAccess access(isolate_); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 484 | thread_local_.interrupt_flags_ &= ~static_cast<int>(after_what); |
whesse@chromium.org | b6e43bb | 2010-04-14 09:36:28 +0000 | [diff] [blame] | 485 | if (!should_postpone_interrupts(access) && !has_pending_interrupts(access)) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 486 | reset_limits(access); |
| 487 | } |
| 488 | } |
| 489 | |
| 490 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 491 | char* StackGuard::ArchiveStackGuard(char* to) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 492 | ExecutionAccess access(isolate_); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 493 | memcpy(to, reinterpret_cast<char*>(&thread_local_), sizeof(ThreadLocal)); |
| 494 | ThreadLocal blank; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 495 | |
| 496 | // Set the stack limits using the old thread_local_. |
| 497 | // TODO(isolates): This was the old semantics of constructing a ThreadLocal |
| 498 | // (as the ctor called SetStackLimits, which looked at the |
| 499 | // current thread_local_ from StackGuard)-- but is this |
| 500 | // really what was intended? |
| 501 | isolate_->heap()->SetStackLimits(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 502 | thread_local_ = blank; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 503 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 504 | return to + sizeof(ThreadLocal); |
| 505 | } |
| 506 | |
| 507 | |
| 508 | char* StackGuard::RestoreStackGuard(char* from) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 509 | ExecutionAccess access(isolate_); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 510 | memcpy(reinterpret_cast<char*>(&thread_local_), from, sizeof(ThreadLocal)); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 511 | isolate_->heap()->SetStackLimits(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 512 | return from + sizeof(ThreadLocal); |
| 513 | } |
| 514 | |
| 515 | |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 516 | void StackGuard::FreeThreadResources() { |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 517 | Isolate::PerIsolateThreadData* per_thread = |
| 518 | isolate_->FindOrAllocatePerThreadDataForThisThread(); |
| 519 | per_thread->set_stack_limit(thread_local_.real_climit_); |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 520 | } |
| 521 | |
| 522 | |
| 523 | void StackGuard::ThreadLocal::Clear() { |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 524 | real_jslimit_ = kIllegalLimit; |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 525 | jslimit_ = kIllegalLimit; |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 526 | real_climit_ = kIllegalLimit; |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 527 | climit_ = kIllegalLimit; |
| 528 | nesting_ = 0; |
| 529 | postpone_interrupts_nesting_ = 0; |
| 530 | interrupt_flags_ = 0; |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 531 | } |
| 532 | |
| 533 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 534 | bool StackGuard::ThreadLocal::Initialize(Isolate* isolate) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 535 | bool should_set_stack_limits = false; |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 536 | if (real_climit_ == kIllegalLimit) { |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 537 | // Takes the address of the limit variable in order to find out where |
| 538 | // the top of stack is right now. |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 539 | const uintptr_t kLimitSize = FLAG_stack_size * KB; |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 540 | uintptr_t limit = reinterpret_cast<uintptr_t>(&limit) - kLimitSize; |
| 541 | ASSERT(reinterpret_cast<uintptr_t>(&limit) > kLimitSize); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 542 | real_jslimit_ = SimulatorStack::JsLimitFromCLimit(isolate, limit); |
| 543 | jslimit_ = SimulatorStack::JsLimitFromCLimit(isolate, limit); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 544 | real_climit_ = limit; |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 545 | climit_ = limit; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 546 | should_set_stack_limits = true; |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 547 | } |
| 548 | nesting_ = 0; |
| 549 | postpone_interrupts_nesting_ = 0; |
| 550 | interrupt_flags_ = 0; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 551 | return should_set_stack_limits; |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 552 | } |
| 553 | |
| 554 | |
| 555 | void StackGuard::ClearThread(const ExecutionAccess& lock) { |
| 556 | thread_local_.Clear(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 557 | isolate_->heap()->SetStackLimits(); |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 558 | } |
| 559 | |
| 560 | |
| 561 | void StackGuard::InitThread(const ExecutionAccess& lock) { |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 562 | if (thread_local_.Initialize(isolate_)) isolate_->heap()->SetStackLimits(); |
| 563 | Isolate::PerIsolateThreadData* per_thread = |
| 564 | isolate_->FindOrAllocatePerThreadDataForThisThread(); |
| 565 | uintptr_t stored_limit = per_thread->stack_limit(); |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 566 | // You should hold the ExecutionAccess lock when you call this. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 567 | if (stored_limit != 0) { |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 568 | SetStackLimit(stored_limit); |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 569 | } |
| 570 | } |
| 571 | |
| 572 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 573 | // --- C a l l s t o n a t i v e s --- |
| 574 | |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 575 | #define RETURN_NATIVE_CALL(name, args, has_pending_exception) \ |
| 576 | do { \ |
| 577 | Isolate* isolate = Isolate::Current(); \ |
| 578 | Handle<Object> argv[] = args; \ |
| 579 | ASSERT(has_pending_exception != NULL); \ |
| 580 | return Call(isolate->name##_fun(), \ |
| 581 | isolate->js_builtins_object(), \ |
| 582 | ARRAY_SIZE(argv), argv, \ |
| 583 | has_pending_exception); \ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 584 | } while (false) |
| 585 | |
| 586 | |
| 587 | Handle<Object> Execution::ToBoolean(Handle<Object> obj) { |
| 588 | // See the similar code in runtime.js:ToBoolean. |
| 589 | if (obj->IsBoolean()) return obj; |
| 590 | bool result = true; |
| 591 | if (obj->IsString()) { |
| 592 | result = Handle<String>::cast(obj)->length() != 0; |
| 593 | } else if (obj->IsNull() || obj->IsUndefined()) { |
| 594 | result = false; |
| 595 | } else if (obj->IsNumber()) { |
| 596 | double value = obj->Number(); |
| 597 | result = !((value == 0) || isnan(value)); |
| 598 | } |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 599 | return Handle<Object>(HEAP->ToBoolean(result)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 600 | } |
| 601 | |
| 602 | |
| 603 | Handle<Object> Execution::ToNumber(Handle<Object> obj, bool* exc) { |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 604 | RETURN_NATIVE_CALL(to_number, { obj }, exc); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 605 | } |
| 606 | |
| 607 | |
| 608 | Handle<Object> Execution::ToString(Handle<Object> obj, bool* exc) { |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 609 | RETURN_NATIVE_CALL(to_string, { obj }, exc); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 610 | } |
| 611 | |
| 612 | |
| 613 | Handle<Object> Execution::ToDetailString(Handle<Object> obj, bool* exc) { |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 614 | RETURN_NATIVE_CALL(to_detail_string, { obj }, exc); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 615 | } |
| 616 | |
| 617 | |
| 618 | Handle<Object> Execution::ToObject(Handle<Object> obj, bool* exc) { |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 619 | if (obj->IsSpecObject()) return obj; |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 620 | RETURN_NATIVE_CALL(to_object, { obj }, exc); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 621 | } |
| 622 | |
| 623 | |
| 624 | Handle<Object> Execution::ToInteger(Handle<Object> obj, bool* exc) { |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 625 | RETURN_NATIVE_CALL(to_integer, { obj }, exc); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 626 | } |
| 627 | |
| 628 | |
| 629 | Handle<Object> Execution::ToUint32(Handle<Object> obj, bool* exc) { |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 630 | RETURN_NATIVE_CALL(to_uint32, { obj }, exc); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 631 | } |
| 632 | |
| 633 | |
| 634 | Handle<Object> Execution::ToInt32(Handle<Object> obj, bool* exc) { |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 635 | RETURN_NATIVE_CALL(to_int32, { obj }, exc); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 636 | } |
| 637 | |
| 638 | |
| 639 | Handle<Object> Execution::NewDate(double time, bool* exc) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 640 | Handle<Object> time_obj = FACTORY->NewNumber(time); |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 641 | RETURN_NATIVE_CALL(create_date, { time_obj }, exc); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 642 | } |
| 643 | |
| 644 | |
| 645 | #undef RETURN_NATIVE_CALL |
| 646 | |
| 647 | |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 648 | Handle<JSRegExp> Execution::NewJSRegExp(Handle<String> pattern, |
| 649 | Handle<String> flags, |
| 650 | bool* exc) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 651 | Handle<JSFunction> function = Handle<JSFunction>( |
| 652 | pattern->GetIsolate()->global_context()->regexp_function()); |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 653 | Handle<Object> re_obj = RegExpImpl::CreateRegExpLiteral( |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 654 | function, pattern, flags, exc); |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 655 | if (*exc) return Handle<JSRegExp>(); |
| 656 | return Handle<JSRegExp>::cast(re_obj); |
| 657 | } |
| 658 | |
| 659 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 660 | Handle<Object> Execution::CharAt(Handle<String> string, uint32_t index) { |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 661 | Isolate* isolate = string->GetIsolate(); |
| 662 | Factory* factory = isolate->factory(); |
| 663 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 664 | int int_index = static_cast<int>(index); |
| 665 | if (int_index < 0 || int_index >= string->length()) { |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 666 | return factory->undefined_value(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 667 | } |
| 668 | |
| 669 | Handle<Object> char_at = |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 670 | GetProperty(isolate->js_builtins_object(), |
| 671 | factory->char_at_symbol()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 672 | if (!char_at->IsJSFunction()) { |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 673 | return factory->undefined_value(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 674 | } |
| 675 | |
| 676 | bool caught_exception; |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 677 | Handle<Object> index_object = factory->NewNumberFromInt(int_index); |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 678 | Handle<Object> index_arg[] = { index_object }; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 679 | Handle<Object> result = TryCall(Handle<JSFunction>::cast(char_at), |
| 680 | string, |
| 681 | ARRAY_SIZE(index_arg), |
| 682 | index_arg, |
| 683 | &caught_exception); |
| 684 | if (caught_exception) { |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 685 | return factory->undefined_value(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 686 | } |
| 687 | return result; |
| 688 | } |
| 689 | |
| 690 | |
| 691 | Handle<JSFunction> Execution::InstantiateFunction( |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 692 | Handle<FunctionTemplateInfo> data, |
| 693 | bool* exc) { |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 694 | Isolate* isolate = data->GetIsolate(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 695 | // Fast case: see if the function has already been instantiated |
| 696 | int serial_number = Smi::cast(data->serial_number())->value(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 697 | Object* elm = |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 698 | isolate->global_context()->function_cache()-> |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 699 | GetElementNoExceptionThrown(serial_number); |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 700 | if (elm->IsJSFunction()) return Handle<JSFunction>(JSFunction::cast(elm)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 701 | // The function has not yet been instantiated in this context; do it. |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 702 | Handle<Object> args[] = { data }; |
| 703 | Handle<Object> result = Call(isolate->instantiate_fun(), |
| 704 | isolate->js_builtins_object(), |
| 705 | ARRAY_SIZE(args), |
| 706 | args, |
| 707 | exc); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 708 | if (*exc) return Handle<JSFunction>::null(); |
| 709 | return Handle<JSFunction>::cast(result); |
| 710 | } |
| 711 | |
| 712 | |
| 713 | Handle<JSObject> Execution::InstantiateObject(Handle<ObjectTemplateInfo> data, |
| 714 | bool* exc) { |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 715 | Isolate* isolate = data->GetIsolate(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 716 | if (data->property_list()->IsUndefined() && |
| 717 | !data->constructor()->IsUndefined()) { |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 718 | // Initialization to make gcc happy. |
| 719 | Object* result = NULL; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 720 | { |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 721 | HandleScope scope(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 722 | Handle<FunctionTemplateInfo> cons_template = |
| 723 | Handle<FunctionTemplateInfo>( |
| 724 | FunctionTemplateInfo::cast(data->constructor())); |
| 725 | Handle<JSFunction> cons = InstantiateFunction(cons_template, exc); |
| 726 | if (*exc) return Handle<JSObject>::null(); |
| 727 | Handle<Object> value = New(cons, 0, NULL, exc); |
| 728 | if (*exc) return Handle<JSObject>::null(); |
| 729 | result = *value; |
| 730 | } |
| 731 | ASSERT(!*exc); |
| 732 | return Handle<JSObject>(JSObject::cast(result)); |
| 733 | } else { |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 734 | Handle<Object> args[] = { data }; |
| 735 | Handle<Object> result = Call(isolate->instantiate_fun(), |
| 736 | isolate->js_builtins_object(), |
| 737 | ARRAY_SIZE(args), |
| 738 | args, |
| 739 | exc); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 740 | if (*exc) return Handle<JSObject>::null(); |
| 741 | return Handle<JSObject>::cast(result); |
| 742 | } |
| 743 | } |
| 744 | |
| 745 | |
| 746 | void Execution::ConfigureInstance(Handle<Object> instance, |
| 747 | Handle<Object> instance_template, |
| 748 | bool* exc) { |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 749 | Isolate* isolate = Isolate::Current(); |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 750 | Handle<Object> args[] = { instance, instance_template }; |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 751 | Execution::Call(isolate->configure_instance_fun(), |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 752 | isolate->js_builtins_object(), |
| 753 | ARRAY_SIZE(args), |
| 754 | args, |
| 755 | exc); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 756 | } |
| 757 | |
| 758 | |
| 759 | Handle<String> Execution::GetStackTraceLine(Handle<Object> recv, |
| 760 | Handle<JSFunction> fun, |
| 761 | Handle<Object> pos, |
| 762 | Handle<Object> is_global) { |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 763 | Isolate* isolate = fun->GetIsolate(); |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 764 | Handle<Object> args[] = { recv, fun, pos, is_global }; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 765 | bool caught_exception; |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 766 | Handle<Object> result = TryCall(isolate->get_stack_trace_line_fun(), |
| 767 | isolate->js_builtins_object(), |
| 768 | ARRAY_SIZE(args), |
| 769 | args, |
| 770 | &caught_exception); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 771 | if (caught_exception || !result->IsString()) { |
| 772 | return isolate->factory()->empty_symbol(); |
| 773 | } |
| 774 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 775 | return Handle<String>::cast(result); |
| 776 | } |
| 777 | |
| 778 | |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 779 | static Object* RuntimePreempt() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 780 | Isolate* isolate = Isolate::Current(); |
| 781 | |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 782 | // Clear the preempt request flag. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 783 | isolate->stack_guard()->Continue(PREEMPT); |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 784 | |
| 785 | ContextSwitcher::PreemptionReceived(); |
| 786 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 787 | #ifdef ENABLE_DEBUGGER_SUPPORT |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 788 | if (isolate->debug()->InDebugger()) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 789 | // If currently in the debugger don't do any actual preemption but record |
| 790 | // that preemption occoured while in the debugger. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 791 | isolate->debug()->PreemptionWhileInDebugger(); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 792 | } else { |
| 793 | // Perform preemption. |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 794 | v8::Unlocker unlocker(reinterpret_cast<v8::Isolate*>(isolate)); |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 795 | Thread::YieldCPU(); |
| 796 | } |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 797 | #else |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 798 | { // NOLINT |
| 799 | // Perform preemption. |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 800 | v8::Unlocker unlocker(reinterpret_cast<v8::Isolate*>(isolate)); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 801 | Thread::YieldCPU(); |
| 802 | } |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 803 | #endif |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 804 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 805 | return isolate->heap()->undefined_value(); |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 806 | } |
| 807 | |
| 808 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 809 | #ifdef ENABLE_DEBUGGER_SUPPORT |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 810 | Object* Execution::DebugBreakHelper() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 811 | Isolate* isolate = Isolate::Current(); |
| 812 | |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 813 | // Just continue if breaks are disabled. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 814 | if (isolate->debug()->disable_break()) { |
| 815 | return isolate->heap()->undefined_value(); |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 816 | } |
| 817 | |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 818 | // Ignore debug break during bootstrapping. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 819 | if (isolate->bootstrapper()->IsActive()) { |
| 820 | return isolate->heap()->undefined_value(); |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 821 | } |
| 822 | |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 823 | { |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 824 | JavaScriptFrameIterator it(isolate); |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 825 | ASSERT(!it.done()); |
| 826 | Object* fun = it.frame()->function(); |
| 827 | if (fun && fun->IsJSFunction()) { |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 828 | // Don't stop in builtin functions. |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 829 | if (JSFunction::cast(fun)->IsBuiltin()) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 830 | return isolate->heap()->undefined_value(); |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 831 | } |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 832 | GlobalObject* global = JSFunction::cast(fun)->context()->global(); |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 833 | // Don't stop in debugger functions. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 834 | if (isolate->debug()->IsDebugGlobal(global)) { |
| 835 | return isolate->heap()->undefined_value(); |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 836 | } |
| 837 | } |
| 838 | } |
| 839 | |
sgjesse@chromium.org | 755c5b1 | 2009-05-29 11:04:38 +0000 | [diff] [blame] | 840 | // Collect the break state before clearing the flags. |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 841 | bool debug_command_only = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 842 | isolate->stack_guard()->IsDebugCommand() && |
| 843 | !isolate->stack_guard()->IsDebugBreak(); |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 844 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 845 | // Clear the debug break request flag. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 846 | isolate->stack_guard()->Continue(DEBUGBREAK); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 847 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 848 | ProcessDebugMessages(debug_command_only); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 849 | |
| 850 | // Return to continue execution. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 851 | return isolate->heap()->undefined_value(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 852 | } |
| 853 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 854 | void Execution::ProcessDebugMessages(bool debug_command_only) { |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 855 | Isolate* isolate = Isolate::Current(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 856 | // Clear the debug command request flag. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 857 | isolate->stack_guard()->Continue(DEBUGCOMMAND); |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 858 | |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 859 | HandleScope scope(isolate); |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 860 | // Enter the debugger. Just continue if we fail to enter the debugger. |
| 861 | EnterDebugger debugger; |
| 862 | if (debugger.FailedToEnter()) { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 863 | return; |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 864 | } |
| 865 | |
sgjesse@chromium.org | 755c5b1 | 2009-05-29 11:04:38 +0000 | [diff] [blame] | 866 | // Notify the debug event listeners. Indicate auto continue if the break was |
| 867 | // a debug command break. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 868 | isolate->debugger()->OnDebugBreak(isolate->factory()->undefined_value(), |
| 869 | debug_command_only); |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 870 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 871 | |
| 872 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 873 | #endif |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 874 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 875 | MaybeObject* Execution::HandleStackGuardInterrupt() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 876 | Isolate* isolate = Isolate::Current(); |
| 877 | StackGuard* stack_guard = isolate->stack_guard(); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 878 | |
| 879 | if (stack_guard->IsGCRequest()) { |
rossberg@chromium.org | 994edf6 | 2012-02-06 10:12:55 +0000 | [diff] [blame^] | 880 | isolate->heap()->CollectAllGarbage(false, "StackGuard GC request"); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 881 | stack_guard->Continue(GC_REQUEST); |
| 882 | } |
| 883 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 884 | isolate->counters()->stack_interrupts()->Increment(); |
| 885 | if (stack_guard->IsRuntimeProfilerTick()) { |
| 886 | isolate->counters()->runtime_profiler_ticks()->Increment(); |
| 887 | stack_guard->Continue(RUNTIME_PROFILER_TICK); |
| 888 | isolate->runtime_profiler()->OptimizeNow(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 889 | } |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 890 | #ifdef ENABLE_DEBUGGER_SUPPORT |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 891 | if (stack_guard->IsDebugBreak() || stack_guard->IsDebugCommand()) { |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 892 | DebugBreakHelper(); |
| 893 | } |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 894 | #endif |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 895 | if (stack_guard->IsPreempted()) RuntimePreempt(); |
| 896 | if (stack_guard->IsTerminateExecution()) { |
| 897 | stack_guard->Continue(TERMINATE); |
| 898 | return isolate->TerminateExecution(); |
sgjesse@chromium.org | c81c894 | 2009-08-21 10:54:26 +0000 | [diff] [blame] | 899 | } |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 900 | if (stack_guard->IsInterrupted()) { |
| 901 | stack_guard->Continue(INTERRUPT); |
| 902 | return isolate->StackOverflow(); |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 903 | } |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 904 | return isolate->heap()->undefined_value(); |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 905 | } |
| 906 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 907 | } } // namespace v8::internal |