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

Unified Diff: src/runtime/runtime-array.cc

Issue 975463002: Implement subclassing Arrays. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fix arm again Created 5 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/runtime/runtime.h ('k') | src/x64/code-stubs-x64.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/runtime/runtime-array.cc
diff --git a/src/runtime/runtime-array.cc b/src/runtime/runtime-array.cc
index 6d8a11e2407530ab9b52a5371d8218c3088e65a8..8d7b946fb38b106a82bf3ed04b755cff1e42f1db 100644
--- a/src/runtime/runtime-array.cc
+++ b/src/runtime/runtime-array.cc
@@ -1038,6 +1038,7 @@ RUNTIME_FUNCTION(Runtime_GetArrayKeys) {
static Object* ArrayConstructorCommon(Isolate* isolate,
Handle<JSFunction> constructor,
+ Handle<JSFunction> original_constructor,
Handle<AllocationSite> site,
Arguments* caller_args) {
Factory* factory = isolate->factory();
@@ -1109,6 +1110,19 @@ static Object* ArrayConstructorCommon(Isolate* isolate,
// We must mark the allocationsite as un-inlinable.
site->SetDoNotInlineCall();
}
+
+ // Set up the prototoype using original function.
+ // TODO(dslomov): instead of setting the __proto__,
+ // use and cache the correct map.
+ if (*original_constructor != *constructor) {
+ if (original_constructor->has_instance_prototype()) {
+ Handle<Object> prototype =
+ handle(original_constructor->instance_prototype(), isolate);
+ RETURN_FAILURE_ON_EXCEPTION(
+ isolate, JSObject::SetPrototype(array, prototype, false));
+ }
+ }
+
return *array;
}
@@ -1142,7 +1156,27 @@ RUNTIME_FUNCTION(Runtime_ArrayConstructor) {
DCHECK(!site->SitePointsToLiteral());
}
- return ArrayConstructorCommon(isolate, constructor, site, caller_args);
+ return ArrayConstructorCommon(isolate, constructor, constructor, site,
+ caller_args);
+}
+
+
+RUNTIME_FUNCTION(Runtime_ArrayConstructorWithSubclassing) {
+ HandleScope scope(isolate);
+ int args_length = args.length();
+ CHECK(args_length >= 2);
arv (Not doing code reviews) 2015/03/03 18:15:20 Does this need to be a CHECK and not a DCHECK?
Dmitry Lomov (no reviews) 2015/03/03 18:18:08 CHECK is safer (and does not cost us much)
+
+ // This variables and checks work around -Werror=strict-overflow.
+ int pre_last_arg_index = args_length - 2;
+ int last_arg_index = args_length - 1;
+ CHECK(pre_last_arg_index >= 0);
+ CHECK(last_arg_index >= 0);
+
+ CONVERT_ARG_HANDLE_CHECKED(JSFunction, constructor, pre_last_arg_index);
+ CONVERT_ARG_HANDLE_CHECKED(JSFunction, original_constructor, last_arg_index);
+ Arguments caller_args(args_length - 2, args.arguments());
+ return ArrayConstructorCommon(isolate, constructor, original_constructor,
+ Handle<AllocationSite>::null(), &caller_args);
}
@@ -1161,7 +1195,7 @@ RUNTIME_FUNCTION(Runtime_InternalArrayConstructor) {
DCHECK(arg_count == caller_args->length());
}
#endif
- return ArrayConstructorCommon(isolate, constructor,
+ return ArrayConstructorCommon(isolate, constructor, constructor,
Handle<AllocationSite>::null(), caller_args);
}
« no previous file with comments | « src/runtime/runtime.h ('k') | src/x64/code-stubs-x64.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698