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

Side by Side Diff: src/execution.cc

Issue 6883045: Add CallAsFunction method to the Object class in the API (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Fix failure in debug mode 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
« no previous file with comments | « src/execution.h ('k') | test/cctest/test-api.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 if (object->IsHeapObject() && 227 if (object->IsHeapObject() &&
228 HeapObject::cast(*object)->map()->has_instance_call_handler()) { 228 HeapObject::cast(*object)->map()->has_instance_call_handler()) {
229 return Handle<JSFunction>( 229 return Handle<JSFunction>(
230 isolate->global_context()->call_as_function_delegate()); 230 isolate->global_context()->call_as_function_delegate());
231 } 231 }
232 232
233 return factory->undefined_value(); 233 return factory->undefined_value();
234 } 234 }
235 235
236 236
237 Handle<Object> Execution::TryGetFunctionDelegate(Handle<Object> object,
238 bool* has_pending_exception) {
239 ASSERT(!object->IsJSFunction());
240 Isolate* isolate = Isolate::Current();
241
242 // Objects created through the API can have an instance-call handler
243 // that should be used when calling the object as a function.
244 if (object->IsHeapObject() &&
245 HeapObject::cast(*object)->map()->has_instance_call_handler()) {
246 return Handle<JSFunction>(
247 isolate->global_context()->call_as_function_delegate());
248 }
249
250 // If the Object doesn't have an instance-call handler we should
251 // throw a non-callable exception.
252 i::Handle<i::Object> error_obj = isolate->factory()->NewTypeError(
253 "called_non_callable", i::HandleVector<i::Object>(&object, 1));
254 isolate->Throw(*error_obj);
255 *has_pending_exception = true;
256
257 return isolate->factory()->undefined_value();
258 }
259
260
237 Handle<Object> Execution::GetConstructorDelegate(Handle<Object> object) { 261 Handle<Object> Execution::GetConstructorDelegate(Handle<Object> object) {
238 ASSERT(!object->IsJSFunction()); 262 ASSERT(!object->IsJSFunction());
239 Isolate* isolate = Isolate::Current(); 263 Isolate* isolate = Isolate::Current();
240 264
241 // If you return a function from here, it will be called when an 265 // If you return a function from here, it will be called when an
242 // attempt is made to call the given object as a constructor. 266 // attempt is made to call the given object as a constructor.
243 267
244 // Objects created through the API can have an instance-call handler 268 // Objects created through the API can have an instance-call handler
245 // that should be used when calling the object as a function. 269 // that should be used when calling the object as a function.
246 if (object->IsHeapObject() && 270 if (object->IsHeapObject() &&
(...skipping 535 matching lines...) Expand 10 before | Expand all | Expand 10 after
782 return isolate->TerminateExecution(); 806 return isolate->TerminateExecution();
783 } 807 }
784 if (stack_guard->IsInterrupted()) { 808 if (stack_guard->IsInterrupted()) {
785 stack_guard->Continue(INTERRUPT); 809 stack_guard->Continue(INTERRUPT);
786 return isolate->StackOverflow(); 810 return isolate->StackOverflow();
787 } 811 }
788 return isolate->heap()->undefined_value(); 812 return isolate->heap()->undefined_value();
789 } 813 }
790 814
791 } } // namespace v8::internal 815 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/execution.h ('k') | test/cctest/test-api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698