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

Side by Side Diff: src/objects.cc

Issue 7849021: Handle function proxies as getters/setters. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Micro-opt. Created 9 years, 3 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 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 RETURN_IF_SCHEDULED_EXCEPTION(isolate); 205 RETURN_IF_SCHEDULED_EXCEPTION(isolate);
206 if (result.IsEmpty()) { 206 if (result.IsEmpty()) {
207 return isolate->heap()->undefined_value(); 207 return isolate->heap()->undefined_value();
208 } 208 }
209 return *v8::Utils::OpenHandle(*result); 209 return *v8::Utils::OpenHandle(*result);
210 } 210 }
211 211
212 // __defineGetter__ callback 212 // __defineGetter__ callback
213 if (structure->IsFixedArray()) { 213 if (structure->IsFixedArray()) {
214 Object* getter = FixedArray::cast(structure)->get(kGetterIndex); 214 Object* getter = FixedArray::cast(structure)->get(kGetterIndex);
215 if (getter->IsJSFunction()) { 215 if (getter->IsSpecFunction()) {
216 // TODO(rossberg): nicer would be to cast to some JSCallable here...
216 return Object::GetPropertyWithDefinedGetter(receiver, 217 return Object::GetPropertyWithDefinedGetter(receiver,
217 JSFunction::cast(getter)); 218 JSReceiver::cast(getter));
218 } 219 }
219 // Getter is not a function. 220 // Getter is not a function.
220 return isolate->heap()->undefined_value(); 221 return isolate->heap()->undefined_value();
221 } 222 }
222 223
223 UNREACHABLE(); 224 UNREACHABLE();
224 return NULL; 225 return NULL;
225 } 226 }
226 227
227 228
(...skipping 20 matching lines...) Expand all
248 bool has_exception; 249 bool has_exception;
249 Handle<Object> result = 250 Handle<Object> result =
250 Execution::Call(trap, handler, ARRAY_SIZE(args), args, &has_exception); 251 Execution::Call(trap, handler, ARRAY_SIZE(args), args, &has_exception);
251 if (has_exception) return Failure::Exception(); 252 if (has_exception) return Failure::Exception();
252 253
253 return *result; 254 return *result;
254 } 255 }
255 256
256 257
257 MaybeObject* Object::GetPropertyWithDefinedGetter(Object* receiver, 258 MaybeObject* Object::GetPropertyWithDefinedGetter(Object* receiver,
258 JSFunction* getter) { 259 JSReceiver* getter) {
259 HandleScope scope; 260 HandleScope scope;
260 Handle<JSFunction> fun(JSFunction::cast(getter)); 261 Handle<JSReceiver> fun(JSReceiver::cast(getter));
261 Handle<Object> self(receiver); 262 Handle<Object> self(receiver);
262 #ifdef ENABLE_DEBUGGER_SUPPORT 263 #ifdef ENABLE_DEBUGGER_SUPPORT
263 Debug* debug = fun->GetHeap()->isolate()->debug(); 264 Debug* debug = fun->GetHeap()->isolate()->debug();
264 // Handle stepping into a getter if step into is active. 265 // Handle stepping into a getter if step into is active.
265 if (debug->StepInActive()) { 266 // TODO(rossberg): should this apply to getters that are function proxies?
266 debug->HandleStepIn(fun, Handle<Object>::null(), 0, false); 267 if (debug->StepInActive() && fun->IsJSFunction()) {
268 debug->HandleStepIn(
269 Handle<JSFunction>::cast(fun), Handle<Object>::null(), 0, false);
267 } 270 }
268 #endif 271 #endif
272
269 bool has_pending_exception; 273 bool has_pending_exception;
270 Handle<Object> result = 274 Handle<Object> result =
271 Execution::Call(fun, self, 0, NULL, &has_pending_exception); 275 Execution::Call(fun, self, 0, NULL, &has_pending_exception);
272 // Check for pending exception and return the result. 276 // Check for pending exception and return the result.
273 if (has_pending_exception) return Failure::Exception(); 277 if (has_pending_exception) return Failure::Exception();
274 return *result; 278 return *result;
275 } 279 }
276 280
277 281
278 // Only deal with CALLBACKS and INTERCEPTOR 282 // Only deal with CALLBACKS and INTERCEPTOR
(...skipping 1594 matching lines...) Expand 10 before | Expand all | Expand 10 after
1873 call_fun(v8::Utils::ToLocal(key), 1877 call_fun(v8::Utils::ToLocal(key),
1874 v8::Utils::ToLocal(value_handle), 1878 v8::Utils::ToLocal(value_handle),
1875 info); 1879 info);
1876 } 1880 }
1877 RETURN_IF_SCHEDULED_EXCEPTION(isolate); 1881 RETURN_IF_SCHEDULED_EXCEPTION(isolate);
1878 return *value_handle; 1882 return *value_handle;
1879 } 1883 }
1880 1884
1881 if (structure->IsFixedArray()) { 1885 if (structure->IsFixedArray()) {
1882 Object* setter = FixedArray::cast(structure)->get(kSetterIndex); 1886 Object* setter = FixedArray::cast(structure)->get(kSetterIndex);
1883 if (setter->IsJSFunction()) { 1887 if (setter->IsJSReceiver()) {
1884 return SetPropertyWithDefinedSetter(JSFunction::cast(setter), value); 1888 return SetPropertyWithDefinedSetter(JSReceiver::cast(setter), value);
1885 } else { 1889 } else {
1886 if (strict_mode == kNonStrictMode) { 1890 if (strict_mode == kNonStrictMode) {
1887 return value; 1891 return value;
1888 } 1892 }
1889 Handle<String> key(name); 1893 Handle<String> key(name);
1890 Handle<Object> holder_handle(holder, isolate); 1894 Handle<Object> holder_handle(holder, isolate);
1891 Handle<Object> args[2] = { key, holder_handle }; 1895 Handle<Object> args[2] = { key, holder_handle };
1892 return isolate->Throw( 1896 return isolate->Throw(
1893 *isolate->factory()->NewTypeError("no_setter_in_callback", 1897 *isolate->factory()->NewTypeError("no_setter_in_callback",
1894 HandleVector(args, 2))); 1898 HandleVector(args, 2)));
1895 } 1899 }
1896 } 1900 }
1897 1901
1898 UNREACHABLE(); 1902 UNREACHABLE();
1899 return NULL; 1903 return NULL;
1900 } 1904 }
1901 1905
1902 1906
1903 MaybeObject* JSObject::SetPropertyWithDefinedSetter(JSFunction* setter, 1907 MaybeObject* JSObject::SetPropertyWithDefinedSetter(JSReceiver* setter,
1904 Object* value) { 1908 Object* value) {
1905 Isolate* isolate = GetIsolate(); 1909 Isolate* isolate = GetIsolate();
1906 Handle<Object> value_handle(value, isolate); 1910 Handle<Object> value_handle(value, isolate);
1907 Handle<JSFunction> fun(JSFunction::cast(setter), isolate); 1911 Handle<JSReceiver> fun(JSReceiver::cast(setter), isolate);
1908 Handle<JSObject> self(this, isolate); 1912 Handle<JSObject> self(this, isolate);
1909 #ifdef ENABLE_DEBUGGER_SUPPORT 1913 #ifdef ENABLE_DEBUGGER_SUPPORT
1910 Debug* debug = isolate->debug(); 1914 Debug* debug = isolate->debug();
1911 // Handle stepping into a setter if step into is active. 1915 // Handle stepping into a setter if step into is active.
1912 if (debug->StepInActive()) { 1916 // TODO(rossberg): should this apply to getters that are function proxies?
1913 debug->HandleStepIn(fun, Handle<Object>::null(), 0, false); 1917 if (debug->StepInActive() && fun->IsJSFunction()) {
1918 debug->HandleStepIn(
1919 Handle<JSFunction>::cast(fun), Handle<Object>::null(), 0, false);
1914 } 1920 }
1915 #endif 1921 #endif
1916 bool has_pending_exception; 1922 bool has_pending_exception;
1917 Object** argv[] = { value_handle.location() }; 1923 Object** argv[] = { value_handle.location() };
1918 Execution::Call(fun, self, 1, argv, &has_pending_exception); 1924 Execution::Call(fun, self, 1, argv, &has_pending_exception);
1919 // Check for pending exception and return the result. 1925 // Check for pending exception and return the result.
1920 if (has_pending_exception) return Failure::Exception(); 1926 if (has_pending_exception) return Failure::Exception();
1921 return *value_handle; 1927 return *value_handle;
1922 } 1928 }
1923 1929
(...skipping 1862 matching lines...) Expand 10 before | Expand all | Expand 10 after
3786 if (!maybe_ok->ToObject(&ok)) return maybe_ok; 3792 if (!maybe_ok->ToObject(&ok)) return maybe_ok;
3787 } 3793 }
3788 } 3794 }
3789 return result; 3795 return result;
3790 } 3796 }
3791 3797
3792 MaybeObject* JSObject::DefineAccessor(String* name, 3798 MaybeObject* JSObject::DefineAccessor(String* name,
3793 bool is_getter, 3799 bool is_getter,
3794 Object* fun, 3800 Object* fun,
3795 PropertyAttributes attributes) { 3801 PropertyAttributes attributes) {
3796 ASSERT(fun->IsJSFunction() || fun->IsUndefined()); 3802 ASSERT(fun->IsSpecFunction() || fun->IsUndefined());
3797 Isolate* isolate = GetIsolate(); 3803 Isolate* isolate = GetIsolate();
3798 // Check access rights if needed. 3804 // Check access rights if needed.
3799 if (IsAccessCheckNeeded() && 3805 if (IsAccessCheckNeeded() &&
3800 !isolate->MayNamedAccess(this, name, v8::ACCESS_SET)) { 3806 !isolate->MayNamedAccess(this, name, v8::ACCESS_SET)) {
3801 isolate->ReportFailedAccessCheck(this, v8::ACCESS_SET); 3807 isolate->ReportFailedAccessCheck(this, v8::ACCESS_SET);
3802 return isolate->heap()->undefined_value(); 3808 return isolate->heap()->undefined_value();
3803 } 3809 }
3804 3810
3805 if (IsJSGlobalProxy()) { 3811 if (IsJSGlobalProxy()) {
3806 Object* proto = GetPrototype(); 3812 Object* proto = GetPrototype();
(...skipping 7784 matching lines...) Expand 10 before | Expand all | Expand 10 after
11591 if (break_point_objects()->IsUndefined()) return 0; 11597 if (break_point_objects()->IsUndefined()) return 0;
11592 // Single break point. 11598 // Single break point.
11593 if (!break_point_objects()->IsFixedArray()) return 1; 11599 if (!break_point_objects()->IsFixedArray()) return 1;
11594 // Multiple break points. 11600 // Multiple break points.
11595 return FixedArray::cast(break_point_objects())->length(); 11601 return FixedArray::cast(break_point_objects())->length();
11596 } 11602 }
11597 #endif 11603 #endif
11598 11604
11599 11605
11600 } } // namespace v8::internal 11606 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/objects.h ('k') | src/objects-inl.h » ('j') | test/mjsunit/harmony/proxies.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698