Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame^] | 1 | // Copyright 2012 the V8 project authors. All rights reserved. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +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" |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 33 | #include "bootstrapper.h" |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 34 | #include "codegen.h" |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 35 | #include "debug.h" |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame^] | 36 | #include "isolate-inl.h" |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 37 | #include "runtime-profiler.h" |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 38 | #include "simulator.h" |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 39 | #include "v8threads.h" |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 40 | #include "vm-state-inl.h" |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 41 | |
| 42 | namespace v8 { |
| 43 | namespace internal { |
| 44 | |
| 45 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [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 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame^] | 69 | static Handle<Object> Invoke(bool is_construct, |
| 70 | Handle<JSFunction> function, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 71 | Handle<Object> receiver, |
| 72 | int argc, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame^] | 73 | Handle<Object> args[], |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 74 | bool* has_pending_exception) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame^] | 75 | Isolate* isolate = function->GetIsolate(); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 76 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 77 | // Entering JavaScript. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 78 | VMState state(isolate, JS); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 79 | |
| 80 | // Placeholder for return value. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 81 | MaybeObject* value = reinterpret_cast<Object*>(kZapValue); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 82 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame^] | 83 | typedef Object* (*JSEntryFunction)(byte* entry, |
| 84 | Object* function, |
| 85 | Object* receiver, |
| 86 | int argc, |
| 87 | Object*** args); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 88 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame^] | 89 | Handle<Code> code = is_construct |
| 90 | ? isolate->factory()->js_construct_entry_code() |
| 91 | : isolate->factory()->js_entry_code(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 92 | |
| 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 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +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. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame^] | 103 | ASSERT(function->context()->global()->IsGlobalObject()); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 104 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 105 | { |
| 106 | // Save and restore context around invocation and block the |
| 107 | // allocation of handles without explicit handle scopes. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 108 | SaveContext save(isolate); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 109 | NoHandleAllocation na; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame^] | 110 | JSEntryFunction stub_entry = FUNCTION_CAST<JSEntryFunction>(code->entry()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 111 | |
| 112 | // Call the function through the right JS entry stub. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [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); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +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(); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 127 | ASSERT(*has_pending_exception == Isolate::Current()->has_pending_exception()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 128 | if (*has_pending_exception) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 129 | isolate->ReportPendingMessages(); |
| 130 | if (isolate->pending_exception() == Failure::OutOfMemoryException()) { |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 131 | if (!isolate->ignore_out_of_memory()) { |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 132 | V8::FatalProcessOutOfMemory("JS", true); |
| 133 | } |
| 134 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 135 | return Handle<Object>(); |
| 136 | } else { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 137 | isolate->clear_pending_message(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 138 | } |
| 139 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 140 | return Handle<Object>(value->ToObjectUnchecked(), isolate); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 144 | Handle<Object> Execution::Call(Handle<Object> callable, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 145 | Handle<Object> receiver, |
| 146 | int argc, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame^] | 147 | Handle<Object> argv[], |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 148 | bool* pending_exception, |
| 149 | bool convert_receiver) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame^] | 150 | *pending_exception = false; |
| 151 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +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); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 157 | |
| 158 | // In non-strict mode, convert receiver. |
| 159 | if (convert_receiver && !receiver->IsJSReceiver() && |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame^] | 160 | !func->shared()->native() && func->shared()->is_classic_mode()) { |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +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 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame^] | 173 | return Invoke(false, func, receiver, argc, argv, pending_exception); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 174 | } |
| 175 | |
| 176 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [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, |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 182 | pending_exception); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 183 | } |
| 184 | |
| 185 | |
| 186 | Handle<Object> Execution::TryCall(Handle<JSFunction> func, |
| 187 | Handle<Object> receiver, |
| 188 | int argc, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame^] | 189 | Handle<Object> args[], |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 190 | bool* caught_exception) { |
| 191 | // Enter a try-block while executing the JavaScript code. To avoid |
| 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. |
| 195 | v8::TryCatch catcher; |
| 196 | catcher.SetVerbose(false); |
| 197 | catcher.SetCaptureMessage(false); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame^] | 198 | *caught_exception = false; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +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()); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [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(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 211 | } else { |
| 212 | result = v8::Utils::OpenHandle(*catcher.Exception()); |
| 213 | } |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 214 | isolate->OptionalRescheduleException(true); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 215 | } |
| 216 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 217 | ASSERT(!Isolate::Current()->has_pending_exception()); |
| 218 | ASSERT(!Isolate::Current()->external_caught_exception()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 219 | return result; |
| 220 | } |
| 221 | |
| 222 | |
| 223 | Handle<Object> Execution::GetFunctionDelegate(Handle<Object> object) { |
| 224 | ASSERT(!object->IsJSFunction()); |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 225 | Isolate* isolate = Isolate::Current(); |
| 226 | Factory* factory = isolate->factory(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +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 | |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +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 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +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. |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 240 | if (fun->IsHeapObject() && |
| 241 | HeapObject::cast(fun)->map()->has_instance_call_handler()) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 242 | return Handle<JSFunction>( |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 243 | isolate->global_context()->call_as_function_delegate()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 244 | } |
| 245 | |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 246 | return factory->undefined_value(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 247 | } |
| 248 | |
| 249 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +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 | |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +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 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +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. |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 264 | if (fun->IsHeapObject() && |
| 265 | HeapObject::cast(fun)->map()->has_instance_call_handler()) { |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +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 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 281 | Handle<Object> Execution::GetConstructorDelegate(Handle<Object> object) { |
| 282 | ASSERT(!object->IsJSFunction()); |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 283 | Isolate* isolate = Isolate::Current(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +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 | |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +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 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +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. |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 297 | if (fun->IsHeapObject() && |
| 298 | HeapObject::cast(fun)->map()->has_instance_call_handler()) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 299 | return Handle<JSFunction>( |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 300 | isolate->global_context()->call_as_constructor_delegate()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 301 | } |
| 302 | |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 303 | return isolate->factory()->undefined_value(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 304 | } |
| 305 | |
| 306 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +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 | |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +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 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +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. |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 325 | if (fun->IsHeapObject() && |
| 326 | HeapObject::cast(fun)->map()->has_instance_call_handler()) { |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +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 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 342 | bool StackGuard::IsStackOverflow() { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 343 | ExecutionAccess access(isolate_); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 344 | return (thread_local_.jslimit_ != kInterruptLimit && |
| 345 | thread_local_.climit_ != kInterruptLimit); |
| 346 | } |
| 347 | |
| 348 | |
| 349 | void StackGuard::EnableInterrupts() { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 350 | ExecutionAccess access(isolate_); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 351 | if (has_pending_interrupts(access)) { |
| 352 | set_interrupt_limits(access); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 353 | } |
| 354 | } |
| 355 | |
| 356 | |
| 357 | void StackGuard::SetStackLimit(uintptr_t limit) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 358 | ExecutionAccess access(isolate_); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame^] | 359 | // If the current limits are special (e.g. due to a pending interrupt) then |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 360 | // leave them alone. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 361 | uintptr_t jslimit = SimulatorStack::JsLimitFromCLimit(isolate_, limit); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 362 | if (thread_local_.jslimit_ == thread_local_.real_jslimit_) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 363 | thread_local_.jslimit_ = jslimit; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 364 | } |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 365 | if (thread_local_.climit_ == thread_local_.real_climit_) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 366 | thread_local_.climit_ = limit; |
| 367 | } |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 368 | thread_local_.real_climit_ = limit; |
| 369 | thread_local_.real_jslimit_ = jslimit; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 370 | } |
| 371 | |
| 372 | |
| 373 | void StackGuard::DisableInterrupts() { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 374 | ExecutionAccess access(isolate_); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 375 | reset_limits(access); |
| 376 | } |
| 377 | |
| 378 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame^] | 379 | bool StackGuard::ShouldPostponeInterrupts() { |
| 380 | ExecutionAccess access(isolate_); |
| 381 | return should_postpone_interrupts(access); |
| 382 | } |
| 383 | |
| 384 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 385 | bool StackGuard::IsInterrupted() { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 386 | ExecutionAccess access(isolate_); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame^] | 387 | return (thread_local_.interrupt_flags_ & INTERRUPT) != 0; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 388 | } |
| 389 | |
| 390 | |
| 391 | void StackGuard::Interrupt() { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 392 | ExecutionAccess access(isolate_); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 393 | thread_local_.interrupt_flags_ |= INTERRUPT; |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 394 | set_interrupt_limits(access); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 395 | } |
| 396 | |
| 397 | |
| 398 | bool StackGuard::IsPreempted() { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 399 | ExecutionAccess access(isolate_); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 400 | return thread_local_.interrupt_flags_ & PREEMPT; |
| 401 | } |
| 402 | |
| 403 | |
| 404 | void StackGuard::Preempt() { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 405 | ExecutionAccess access(isolate_); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 406 | thread_local_.interrupt_flags_ |= PREEMPT; |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 407 | set_interrupt_limits(access); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 408 | } |
| 409 | |
| 410 | |
| 411 | bool StackGuard::IsTerminateExecution() { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 412 | ExecutionAccess access(isolate_); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame^] | 413 | return (thread_local_.interrupt_flags_ & TERMINATE) != 0; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 414 | } |
| 415 | |
| 416 | |
| 417 | void StackGuard::TerminateExecution() { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 418 | ExecutionAccess access(isolate_); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 419 | thread_local_.interrupt_flags_ |= TERMINATE; |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 420 | set_interrupt_limits(access); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 421 | } |
| 422 | |
| 423 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 424 | bool StackGuard::IsRuntimeProfilerTick() { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 425 | ExecutionAccess access(isolate_); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame^] | 426 | return (thread_local_.interrupt_flags_ & RUNTIME_PROFILER_TICK) != 0; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 427 | } |
| 428 | |
| 429 | |
| 430 | void StackGuard::RequestRuntimeProfilerTick() { |
| 431 | // Ignore calls if we're not optimizing or if we can't get the lock. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 432 | if (FLAG_opt && ExecutionAccess::TryLock(isolate_)) { |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 433 | thread_local_.interrupt_flags_ |= RUNTIME_PROFILER_TICK; |
| 434 | if (thread_local_.postpone_interrupts_nesting_ == 0) { |
| 435 | thread_local_.jslimit_ = thread_local_.climit_ = kInterruptLimit; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 436 | isolate_->heap()->SetStackLimits(); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 437 | } |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 438 | ExecutionAccess::Unlock(isolate_); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 439 | } |
| 440 | } |
| 441 | |
| 442 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame^] | 443 | bool StackGuard::IsGCRequest() { |
| 444 | ExecutionAccess access(isolate_); |
| 445 | return (thread_local_.interrupt_flags_ & GC_REQUEST) != 0; |
| 446 | } |
| 447 | |
| 448 | |
| 449 | void StackGuard::RequestGC() { |
| 450 | ExecutionAccess access(isolate_); |
| 451 | thread_local_.interrupt_flags_ |= GC_REQUEST; |
| 452 | if (thread_local_.postpone_interrupts_nesting_ == 0) { |
| 453 | thread_local_.jslimit_ = thread_local_.climit_ = kInterruptLimit; |
| 454 | isolate_->heap()->SetStackLimits(); |
| 455 | } |
| 456 | } |
| 457 | |
| 458 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 459 | #ifdef ENABLE_DEBUGGER_SUPPORT |
| 460 | bool StackGuard::IsDebugBreak() { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 461 | ExecutionAccess access(isolate_); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 462 | return thread_local_.interrupt_flags_ & DEBUGBREAK; |
| 463 | } |
| 464 | |
| 465 | |
| 466 | void StackGuard::DebugBreak() { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 467 | ExecutionAccess access(isolate_); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 468 | thread_local_.interrupt_flags_ |= DEBUGBREAK; |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 469 | set_interrupt_limits(access); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 470 | } |
| 471 | |
| 472 | |
| 473 | bool StackGuard::IsDebugCommand() { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 474 | ExecutionAccess access(isolate_); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 475 | return thread_local_.interrupt_flags_ & DEBUGCOMMAND; |
| 476 | } |
| 477 | |
| 478 | |
| 479 | void StackGuard::DebugCommand() { |
| 480 | if (FLAG_debugger_auto_break) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 481 | ExecutionAccess access(isolate_); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 482 | thread_local_.interrupt_flags_ |= DEBUGCOMMAND; |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 483 | set_interrupt_limits(access); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 484 | } |
| 485 | } |
| 486 | #endif |
| 487 | |
| 488 | void StackGuard::Continue(InterruptFlag after_what) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 489 | ExecutionAccess access(isolate_); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 490 | thread_local_.interrupt_flags_ &= ~static_cast<int>(after_what); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 491 | if (!should_postpone_interrupts(access) && !has_pending_interrupts(access)) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 492 | reset_limits(access); |
| 493 | } |
| 494 | } |
| 495 | |
| 496 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 497 | char* StackGuard::ArchiveStackGuard(char* to) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 498 | ExecutionAccess access(isolate_); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 499 | memcpy(to, reinterpret_cast<char*>(&thread_local_), sizeof(ThreadLocal)); |
| 500 | ThreadLocal blank; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 501 | |
| 502 | // Set the stack limits using the old thread_local_. |
| 503 | // TODO(isolates): This was the old semantics of constructing a ThreadLocal |
| 504 | // (as the ctor called SetStackLimits, which looked at the |
| 505 | // current thread_local_ from StackGuard)-- but is this |
| 506 | // really what was intended? |
| 507 | isolate_->heap()->SetStackLimits(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 508 | thread_local_ = blank; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 509 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 510 | return to + sizeof(ThreadLocal); |
| 511 | } |
| 512 | |
| 513 | |
| 514 | char* StackGuard::RestoreStackGuard(char* from) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 515 | ExecutionAccess access(isolate_); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 516 | memcpy(reinterpret_cast<char*>(&thread_local_), from, sizeof(ThreadLocal)); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 517 | isolate_->heap()->SetStackLimits(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 518 | return from + sizeof(ThreadLocal); |
| 519 | } |
| 520 | |
| 521 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 522 | void StackGuard::FreeThreadResources() { |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 523 | Isolate::PerIsolateThreadData* per_thread = |
| 524 | isolate_->FindOrAllocatePerThreadDataForThisThread(); |
| 525 | per_thread->set_stack_limit(thread_local_.real_climit_); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 526 | } |
| 527 | |
| 528 | |
| 529 | void StackGuard::ThreadLocal::Clear() { |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 530 | real_jslimit_ = kIllegalLimit; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 531 | jslimit_ = kIllegalLimit; |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 532 | real_climit_ = kIllegalLimit; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 533 | climit_ = kIllegalLimit; |
| 534 | nesting_ = 0; |
| 535 | postpone_interrupts_nesting_ = 0; |
| 536 | interrupt_flags_ = 0; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 537 | } |
| 538 | |
| 539 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 540 | bool StackGuard::ThreadLocal::Initialize(Isolate* isolate) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 541 | bool should_set_stack_limits = false; |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 542 | if (real_climit_ == kIllegalLimit) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 543 | // Takes the address of the limit variable in order to find out where |
| 544 | // the top of stack is right now. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 545 | const uintptr_t kLimitSize = FLAG_stack_size * KB; |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 546 | uintptr_t limit = reinterpret_cast<uintptr_t>(&limit) - kLimitSize; |
| 547 | ASSERT(reinterpret_cast<uintptr_t>(&limit) > kLimitSize); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 548 | real_jslimit_ = SimulatorStack::JsLimitFromCLimit(isolate, limit); |
| 549 | jslimit_ = SimulatorStack::JsLimitFromCLimit(isolate, limit); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 550 | real_climit_ = limit; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 551 | climit_ = limit; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 552 | should_set_stack_limits = true; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 553 | } |
| 554 | nesting_ = 0; |
| 555 | postpone_interrupts_nesting_ = 0; |
| 556 | interrupt_flags_ = 0; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 557 | return should_set_stack_limits; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 558 | } |
| 559 | |
| 560 | |
| 561 | void StackGuard::ClearThread(const ExecutionAccess& lock) { |
| 562 | thread_local_.Clear(); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 563 | isolate_->heap()->SetStackLimits(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 564 | } |
| 565 | |
| 566 | |
| 567 | void StackGuard::InitThread(const ExecutionAccess& lock) { |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 568 | if (thread_local_.Initialize(isolate_)) isolate_->heap()->SetStackLimits(); |
| 569 | Isolate::PerIsolateThreadData* per_thread = |
| 570 | isolate_->FindOrAllocatePerThreadDataForThisThread(); |
| 571 | uintptr_t stored_limit = per_thread->stack_limit(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 572 | // You should hold the ExecutionAccess lock when you call this. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 573 | if (stored_limit != 0) { |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 574 | SetStackLimit(stored_limit); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 575 | } |
| 576 | } |
| 577 | |
| 578 | |
| 579 | // --- C a l l s t o n a t i v e s --- |
| 580 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame^] | 581 | #define RETURN_NATIVE_CALL(name, args, has_pending_exception) \ |
| 582 | do { \ |
| 583 | Isolate* isolate = Isolate::Current(); \ |
| 584 | Handle<Object> argv[] = args; \ |
| 585 | ASSERT(has_pending_exception != NULL); \ |
| 586 | return Call(isolate->name##_fun(), \ |
| 587 | isolate->js_builtins_object(), \ |
| 588 | ARRAY_SIZE(argv), argv, \ |
| 589 | has_pending_exception); \ |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 590 | } while (false) |
| 591 | |
| 592 | |
| 593 | Handle<Object> Execution::ToBoolean(Handle<Object> obj) { |
| 594 | // See the similar code in runtime.js:ToBoolean. |
| 595 | if (obj->IsBoolean()) return obj; |
| 596 | bool result = true; |
| 597 | if (obj->IsString()) { |
| 598 | result = Handle<String>::cast(obj)->length() != 0; |
| 599 | } else if (obj->IsNull() || obj->IsUndefined()) { |
| 600 | result = false; |
| 601 | } else if (obj->IsNumber()) { |
| 602 | double value = obj->Number(); |
| 603 | result = !((value == 0) || isnan(value)); |
| 604 | } |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 605 | return Handle<Object>(HEAP->ToBoolean(result)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 606 | } |
| 607 | |
| 608 | |
| 609 | Handle<Object> Execution::ToNumber(Handle<Object> obj, bool* exc) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame^] | 610 | RETURN_NATIVE_CALL(to_number, { obj }, exc); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 611 | } |
| 612 | |
| 613 | |
| 614 | Handle<Object> Execution::ToString(Handle<Object> obj, bool* exc) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame^] | 615 | RETURN_NATIVE_CALL(to_string, { obj }, exc); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 616 | } |
| 617 | |
| 618 | |
| 619 | Handle<Object> Execution::ToDetailString(Handle<Object> obj, bool* exc) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame^] | 620 | RETURN_NATIVE_CALL(to_detail_string, { obj }, exc); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 621 | } |
| 622 | |
| 623 | |
| 624 | Handle<Object> Execution::ToObject(Handle<Object> obj, bool* exc) { |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 625 | if (obj->IsSpecObject()) return obj; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame^] | 626 | RETURN_NATIVE_CALL(to_object, { obj }, exc); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 627 | } |
| 628 | |
| 629 | |
| 630 | Handle<Object> Execution::ToInteger(Handle<Object> obj, bool* exc) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame^] | 631 | RETURN_NATIVE_CALL(to_integer, { obj }, exc); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 632 | } |
| 633 | |
| 634 | |
| 635 | Handle<Object> Execution::ToUint32(Handle<Object> obj, bool* exc) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame^] | 636 | RETURN_NATIVE_CALL(to_uint32, { obj }, exc); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 637 | } |
| 638 | |
| 639 | |
| 640 | Handle<Object> Execution::ToInt32(Handle<Object> obj, bool* exc) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame^] | 641 | RETURN_NATIVE_CALL(to_int32, { obj }, exc); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 642 | } |
| 643 | |
| 644 | |
| 645 | Handle<Object> Execution::NewDate(double time, bool* exc) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 646 | Handle<Object> time_obj = FACTORY->NewNumber(time); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame^] | 647 | RETURN_NATIVE_CALL(create_date, { time_obj }, exc); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 648 | } |
| 649 | |
| 650 | |
| 651 | #undef RETURN_NATIVE_CALL |
| 652 | |
| 653 | |
Ben Murdoch | f87a203 | 2010-10-22 12:50:53 +0100 | [diff] [blame] | 654 | Handle<JSRegExp> Execution::NewJSRegExp(Handle<String> pattern, |
| 655 | Handle<String> flags, |
| 656 | bool* exc) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 657 | Handle<JSFunction> function = Handle<JSFunction>( |
| 658 | pattern->GetIsolate()->global_context()->regexp_function()); |
Ben Murdoch | f87a203 | 2010-10-22 12:50:53 +0100 | [diff] [blame] | 659 | Handle<Object> re_obj = RegExpImpl::CreateRegExpLiteral( |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 660 | function, pattern, flags, exc); |
Ben Murdoch | f87a203 | 2010-10-22 12:50:53 +0100 | [diff] [blame] | 661 | if (*exc) return Handle<JSRegExp>(); |
| 662 | return Handle<JSRegExp>::cast(re_obj); |
| 663 | } |
| 664 | |
| 665 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 666 | Handle<Object> Execution::CharAt(Handle<String> string, uint32_t index) { |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 667 | Isolate* isolate = string->GetIsolate(); |
| 668 | Factory* factory = isolate->factory(); |
| 669 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 670 | int int_index = static_cast<int>(index); |
| 671 | if (int_index < 0 || int_index >= string->length()) { |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 672 | return factory->undefined_value(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 673 | } |
| 674 | |
| 675 | Handle<Object> char_at = |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 676 | GetProperty(isolate->js_builtins_object(), |
| 677 | factory->char_at_symbol()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 678 | if (!char_at->IsJSFunction()) { |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 679 | return factory->undefined_value(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 680 | } |
| 681 | |
| 682 | bool caught_exception; |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 683 | Handle<Object> index_object = factory->NewNumberFromInt(int_index); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame^] | 684 | Handle<Object> index_arg[] = { index_object }; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 685 | Handle<Object> result = TryCall(Handle<JSFunction>::cast(char_at), |
| 686 | string, |
| 687 | ARRAY_SIZE(index_arg), |
| 688 | index_arg, |
| 689 | &caught_exception); |
| 690 | if (caught_exception) { |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 691 | return factory->undefined_value(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 692 | } |
| 693 | return result; |
| 694 | } |
| 695 | |
| 696 | |
| 697 | Handle<JSFunction> Execution::InstantiateFunction( |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame^] | 698 | Handle<FunctionTemplateInfo> data, |
| 699 | bool* exc) { |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 700 | Isolate* isolate = data->GetIsolate(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 701 | // Fast case: see if the function has already been instantiated |
| 702 | int serial_number = Smi::cast(data->serial_number())->value(); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 703 | Object* elm = |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 704 | isolate->global_context()->function_cache()-> |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 705 | GetElementNoExceptionThrown(serial_number); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 706 | if (elm->IsJSFunction()) return Handle<JSFunction>(JSFunction::cast(elm)); |
| 707 | // The function has not yet been instantiated in this context; do it. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame^] | 708 | Handle<Object> args[] = { data }; |
| 709 | Handle<Object> result = Call(isolate->instantiate_fun(), |
| 710 | isolate->js_builtins_object(), |
| 711 | ARRAY_SIZE(args), |
| 712 | args, |
| 713 | exc); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 714 | if (*exc) return Handle<JSFunction>::null(); |
| 715 | return Handle<JSFunction>::cast(result); |
| 716 | } |
| 717 | |
| 718 | |
| 719 | Handle<JSObject> Execution::InstantiateObject(Handle<ObjectTemplateInfo> data, |
| 720 | bool* exc) { |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 721 | Isolate* isolate = data->GetIsolate(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 722 | if (data->property_list()->IsUndefined() && |
| 723 | !data->constructor()->IsUndefined()) { |
| 724 | // Initialization to make gcc happy. |
| 725 | Object* result = NULL; |
| 726 | { |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 727 | HandleScope scope(isolate); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 728 | Handle<FunctionTemplateInfo> cons_template = |
| 729 | Handle<FunctionTemplateInfo>( |
| 730 | FunctionTemplateInfo::cast(data->constructor())); |
| 731 | Handle<JSFunction> cons = InstantiateFunction(cons_template, exc); |
| 732 | if (*exc) return Handle<JSObject>::null(); |
| 733 | Handle<Object> value = New(cons, 0, NULL, exc); |
| 734 | if (*exc) return Handle<JSObject>::null(); |
| 735 | result = *value; |
| 736 | } |
| 737 | ASSERT(!*exc); |
| 738 | return Handle<JSObject>(JSObject::cast(result)); |
| 739 | } else { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame^] | 740 | Handle<Object> args[] = { data }; |
| 741 | Handle<Object> result = Call(isolate->instantiate_fun(), |
| 742 | isolate->js_builtins_object(), |
| 743 | ARRAY_SIZE(args), |
| 744 | args, |
| 745 | exc); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 746 | if (*exc) return Handle<JSObject>::null(); |
| 747 | return Handle<JSObject>::cast(result); |
| 748 | } |
| 749 | } |
| 750 | |
| 751 | |
| 752 | void Execution::ConfigureInstance(Handle<Object> instance, |
| 753 | Handle<Object> instance_template, |
| 754 | bool* exc) { |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 755 | Isolate* isolate = Isolate::Current(); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame^] | 756 | Handle<Object> args[] = { instance, instance_template }; |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 757 | Execution::Call(isolate->configure_instance_fun(), |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame^] | 758 | isolate->js_builtins_object(), |
| 759 | ARRAY_SIZE(args), |
| 760 | args, |
| 761 | exc); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 762 | } |
| 763 | |
| 764 | |
| 765 | Handle<String> Execution::GetStackTraceLine(Handle<Object> recv, |
| 766 | Handle<JSFunction> fun, |
| 767 | Handle<Object> pos, |
| 768 | Handle<Object> is_global) { |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 769 | Isolate* isolate = fun->GetIsolate(); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame^] | 770 | Handle<Object> args[] = { recv, fun, pos, is_global }; |
| 771 | bool caught_exception; |
| 772 | Handle<Object> result = TryCall(isolate->get_stack_trace_line_fun(), |
| 773 | isolate->js_builtins_object(), |
| 774 | ARRAY_SIZE(args), |
| 775 | args, |
| 776 | &caught_exception); |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 777 | if (caught_exception || !result->IsString()) { |
| 778 | return isolate->factory()->empty_symbol(); |
| 779 | } |
| 780 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 781 | return Handle<String>::cast(result); |
| 782 | } |
| 783 | |
| 784 | |
| 785 | static Object* RuntimePreempt() { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 786 | Isolate* isolate = Isolate::Current(); |
| 787 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 788 | // Clear the preempt request flag. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 789 | isolate->stack_guard()->Continue(PREEMPT); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 790 | |
| 791 | ContextSwitcher::PreemptionReceived(); |
| 792 | |
| 793 | #ifdef ENABLE_DEBUGGER_SUPPORT |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 794 | if (isolate->debug()->InDebugger()) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 795 | // If currently in the debugger don't do any actual preemption but record |
| 796 | // that preemption occoured while in the debugger. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 797 | isolate->debug()->PreemptionWhileInDebugger(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 798 | } else { |
| 799 | // Perform preemption. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 800 | v8::Unlocker unlocker(reinterpret_cast<v8::Isolate*>(isolate)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 801 | Thread::YieldCPU(); |
| 802 | } |
| 803 | #else |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 804 | { // NOLINT |
| 805 | // Perform preemption. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 806 | v8::Unlocker unlocker(reinterpret_cast<v8::Isolate*>(isolate)); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 807 | Thread::YieldCPU(); |
| 808 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 809 | #endif |
| 810 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 811 | return isolate->heap()->undefined_value(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 812 | } |
| 813 | |
| 814 | |
| 815 | #ifdef ENABLE_DEBUGGER_SUPPORT |
| 816 | Object* Execution::DebugBreakHelper() { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 817 | Isolate* isolate = Isolate::Current(); |
| 818 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 819 | // Just continue if breaks are disabled. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 820 | if (isolate->debug()->disable_break()) { |
| 821 | return isolate->heap()->undefined_value(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 822 | } |
| 823 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 824 | // Ignore debug break during bootstrapping. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 825 | if (isolate->bootstrapper()->IsActive()) { |
| 826 | return isolate->heap()->undefined_value(); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 827 | } |
| 828 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame^] | 829 | StackLimitCheck check(isolate); |
| 830 | if (check.HasOverflowed()) { |
| 831 | return isolate->heap()->undefined_value(); |
| 832 | } |
| 833 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 834 | { |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 835 | JavaScriptFrameIterator it(isolate); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 836 | ASSERT(!it.done()); |
| 837 | Object* fun = it.frame()->function(); |
| 838 | if (fun && fun->IsJSFunction()) { |
| 839 | // Don't stop in builtin functions. |
| 840 | if (JSFunction::cast(fun)->IsBuiltin()) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 841 | return isolate->heap()->undefined_value(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 842 | } |
| 843 | GlobalObject* global = JSFunction::cast(fun)->context()->global(); |
| 844 | // Don't stop in debugger functions. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 845 | if (isolate->debug()->IsDebugGlobal(global)) { |
| 846 | return isolate->heap()->undefined_value(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 847 | } |
| 848 | } |
| 849 | } |
| 850 | |
| 851 | // Collect the break state before clearing the flags. |
| 852 | bool debug_command_only = |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 853 | isolate->stack_guard()->IsDebugCommand() && |
| 854 | !isolate->stack_guard()->IsDebugBreak(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 855 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 856 | // Clear the debug break request flag. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 857 | isolate->stack_guard()->Continue(DEBUGBREAK); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 858 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame^] | 859 | ProcessDebugMessages(debug_command_only); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 860 | |
| 861 | // Return to continue execution. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 862 | return isolate->heap()->undefined_value(); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 863 | } |
| 864 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame^] | 865 | void Execution::ProcessDebugMessages(bool debug_command_only) { |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 866 | Isolate* isolate = Isolate::Current(); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 867 | // Clear the debug command request flag. |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 868 | isolate->stack_guard()->Continue(DEBUGCOMMAND); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 869 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame^] | 870 | StackLimitCheck check(isolate); |
| 871 | if (check.HasOverflowed()) { |
| 872 | return; |
| 873 | } |
| 874 | |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 875 | HandleScope scope(isolate); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 876 | // Enter the debugger. Just continue if we fail to enter the debugger. |
| 877 | EnterDebugger debugger; |
| 878 | if (debugger.FailedToEnter()) { |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 879 | return; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 880 | } |
| 881 | |
| 882 | // Notify the debug event listeners. Indicate auto continue if the break was |
| 883 | // a debug command break. |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 884 | isolate->debugger()->OnDebugBreak(isolate->factory()->undefined_value(), |
| 885 | debug_command_only); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 886 | } |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 887 | |
| 888 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 889 | #endif |
| 890 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame^] | 891 | MaybeObject* Execution::HandleStackGuardInterrupt(Isolate* isolate) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 892 | StackGuard* stack_guard = isolate->stack_guard(); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame^] | 893 | if (stack_guard->ShouldPostponeInterrupts()) { |
| 894 | return isolate->heap()->undefined_value(); |
| 895 | } |
| 896 | |
| 897 | if (stack_guard->IsGCRequest()) { |
| 898 | isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, |
| 899 | "StackGuard GC request"); |
| 900 | stack_guard->Continue(GC_REQUEST); |
| 901 | } |
| 902 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 903 | isolate->counters()->stack_interrupts()->Increment(); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame^] | 904 | // If FLAG_count_based_interrupts, every interrupt is a profiler interrupt. |
| 905 | if (FLAG_count_based_interrupts || |
| 906 | stack_guard->IsRuntimeProfilerTick()) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 907 | isolate->counters()->runtime_profiler_ticks()->Increment(); |
| 908 | stack_guard->Continue(RUNTIME_PROFILER_TICK); |
| 909 | isolate->runtime_profiler()->OptimizeNow(); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 910 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 911 | #ifdef ENABLE_DEBUGGER_SUPPORT |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 912 | if (stack_guard->IsDebugBreak() || stack_guard->IsDebugCommand()) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 913 | DebugBreakHelper(); |
| 914 | } |
| 915 | #endif |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 916 | if (stack_guard->IsPreempted()) RuntimePreempt(); |
| 917 | if (stack_guard->IsTerminateExecution()) { |
| 918 | stack_guard->Continue(TERMINATE); |
| 919 | return isolate->TerminateExecution(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 920 | } |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 921 | if (stack_guard->IsInterrupted()) { |
| 922 | stack_guard->Continue(INTERRUPT); |
| 923 | return isolate->StackOverflow(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 924 | } |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 925 | return isolate->heap()->undefined_value(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 926 | } |
| 927 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame^] | 928 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 929 | } } // namespace v8::internal |