Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1351)

Side by Side Diff: src/execution.cc

Issue 6902108: Implement CallAsConstructor method for Object in the API (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Add missing testcase Created 9 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 if (object->IsHeapObject() && 270 if (object->IsHeapObject() &&
271 HeapObject::cast(*object)->map()->has_instance_call_handler()) { 271 HeapObject::cast(*object)->map()->has_instance_call_handler()) {
272 return Handle<JSFunction>( 272 return Handle<JSFunction>(
273 isolate->global_context()->call_as_constructor_delegate()); 273 isolate->global_context()->call_as_constructor_delegate());
274 } 274 }
275 275
276 return isolate->factory()->undefined_value(); 276 return isolate->factory()->undefined_value();
277 } 277 }
278 278
279 279
280 Handle<Object> Execution::TryGetConstructorDelegate(
281 Handle<Object> object,
282 bool* has_pending_exception) {
283 ASSERT(!object->IsJSFunction());
284 Isolate* isolate = Isolate::Current();
285
286 // If you return a function from here, it will be called when an
287 // attempt is made to call the given object as a constructor.
288
289 // Objects created through the API can have an instance-call handler
290 // that should be used when calling the object as a function.
291 if (object->IsHeapObject() &&
292 HeapObject::cast(*object)->map()->has_instance_call_handler()) {
293 return Handle<JSFunction>(
294 isolate->global_context()->call_as_constructor_delegate());
295 }
296
297 // If the Object doesn't have an instance-call handler we should
298 // throw a non-callable exception.
299 i::Handle<i::Object> error_obj = isolate->factory()->NewTypeError(
300 "called_non_callable", i::HandleVector<i::Object>(&object, 1));
301 isolate->Throw(*error_obj);
302 *has_pending_exception = true;
303
304 return isolate->factory()->undefined_value();
305 }
306
307
280 bool StackGuard::IsStackOverflow() { 308 bool StackGuard::IsStackOverflow() {
281 ExecutionAccess access(isolate_); 309 ExecutionAccess access(isolate_);
282 return (thread_local_.jslimit_ != kInterruptLimit && 310 return (thread_local_.jslimit_ != kInterruptLimit &&
283 thread_local_.climit_ != kInterruptLimit); 311 thread_local_.climit_ != kInterruptLimit);
284 } 312 }
285 313
286 314
287 void StackGuard::EnableInterrupts() { 315 void StackGuard::EnableInterrupts() {
288 ExecutionAccess access(isolate_); 316 ExecutionAccess access(isolate_);
289 if (has_pending_interrupts(access)) { 317 if (has_pending_interrupts(access)) {
(...skipping 516 matching lines...) Expand 10 before | Expand all | Expand 10 after
806 return isolate->TerminateExecution(); 834 return isolate->TerminateExecution();
807 } 835 }
808 if (stack_guard->IsInterrupted()) { 836 if (stack_guard->IsInterrupted()) {
809 stack_guard->Continue(INTERRUPT); 837 stack_guard->Continue(INTERRUPT);
810 return isolate->StackOverflow(); 838 return isolate->StackOverflow();
811 } 839 }
812 return isolate->heap()->undefined_value(); 840 return isolate->heap()->undefined_value();
813 } 841 }
814 842
815 } } // namespace v8::internal 843 } } // namespace v8::internal
OLDNEW
« src/api.cc ('K') | « src/execution.h ('k') | test/cctest/test-api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698