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