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

Side by Side Diff: src/runtime/runtime-classes.cc

Issue 1316333002: [strong] weak classes can't inherit from strong ones (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: minor comment reorder Created 5 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
« no previous file with comments | « src/runtime/runtime.h ('k') | test/mjsunit/strong/class-object-frozen.js » ('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 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/runtime/runtime-utils.h" 5 #include "src/runtime/runtime-utils.h"
6 6
7 #include <stdlib.h> 7 #include <stdlib.h>
8 #include <limits> 8 #include <limits>
9 9
10 #include "src/arguments.h" 10 #include "src/arguments.h"
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 isolate, 131 isolate,
132 NewTypeError(MessageTemplate::kExtendsValueNotFunction, super_class), 132 NewTypeError(MessageTemplate::kExtendsValueNotFunction, super_class),
133 Object); 133 Object);
134 } 134 }
135 } 135 }
136 136
137 Handle<Map> map = 137 Handle<Map> map =
138 isolate->factory()->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); 138 isolate->factory()->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize);
139 if (constructor->map()->is_strong()) { 139 if (constructor->map()->is_strong()) {
140 map->set_is_strong(); 140 map->set_is_strong();
141 if (super_class->IsNull()) {
142 // Strong class is not permitted to extend null.
143 THROW_NEW_ERROR(isolate, NewTypeError(MessageTemplate::kStrongExtendNull),
144 Object);
145 }
146 } else {
147 if (Handle<HeapObject>::cast(super_class)->map()->is_strong()) {
148 // Weak class is not permitted to extend strong class.
149 THROW_NEW_ERROR(isolate,
150 NewTypeError(MessageTemplate::kStrongWeakExtend, name),
151 Object);
152 }
141 } 153 }
142 Map::SetPrototype(map, prototype_parent); 154 Map::SetPrototype(map, prototype_parent);
143 map->SetConstructor(*constructor); 155 map->SetConstructor(*constructor);
144 Handle<JSObject> prototype = isolate->factory()->NewJSObjectFromMap(map); 156 Handle<JSObject> prototype = isolate->factory()->NewJSObjectFromMap(map);
145 157
146 Handle<String> name_string = name->IsString() 158 Handle<String> name_string = name->IsString()
147 ? Handle<String>::cast(name) 159 ? Handle<String>::cast(name)
148 : isolate->factory()->empty_string(); 160 : isolate->factory()->empty_string();
149 constructor->shared()->set_name(*name_string); 161 constructor->shared()->set_name(*name_string);
150 162
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 CONVERT_SMI_ARG_CHECKED(end_position, 4); 217 CONVERT_SMI_ARG_CHECKED(end_position, 4);
206 218
207 Handle<Object> result; 219 Handle<Object> result;
208 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( 220 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
209 isolate, result, DefineClass(isolate, name, super_class, constructor, 221 isolate, result, DefineClass(isolate, name, super_class, constructor,
210 start_position, end_position)); 222 start_position, end_position));
211 return *result; 223 return *result;
212 } 224 }
213 225
214 226
215 RUNTIME_FUNCTION(Runtime_DefineClassStrong) {
216 HandleScope scope(isolate);
217 DCHECK(args.length() == 5);
218 CONVERT_ARG_HANDLE_CHECKED(Object, name, 0);
219 CONVERT_ARG_HANDLE_CHECKED(Object, super_class, 1);
220 CONVERT_ARG_HANDLE_CHECKED(JSFunction, constructor, 2);
221 CONVERT_SMI_ARG_CHECKED(start_position, 3);
222 CONVERT_SMI_ARG_CHECKED(end_position, 4);
223
224 if (super_class->IsNull()) {
225 THROW_NEW_ERROR_RETURN_FAILURE(
226 isolate, NewTypeError(MessageTemplate::kStrongExtendNull));
227 }
228
229 Handle<Object> result;
230 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
231 isolate, result, DefineClass(isolate, name, super_class, constructor,
232 start_position, end_position));
233 return *result;
234 }
235
236
237 RUNTIME_FUNCTION(Runtime_DefineClassMethod) { 227 RUNTIME_FUNCTION(Runtime_DefineClassMethod) {
238 HandleScope scope(isolate); 228 HandleScope scope(isolate);
239 DCHECK(args.length() == 3); 229 DCHECK(args.length() == 3);
240 CONVERT_ARG_HANDLE_CHECKED(JSObject, object, 0); 230 CONVERT_ARG_HANDLE_CHECKED(JSObject, object, 0);
241 CONVERT_ARG_HANDLE_CHECKED(Name, name, 1); 231 CONVERT_ARG_HANDLE_CHECKED(Name, name, 1);
242 CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 2); 232 CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 2);
243 233
244 RETURN_FAILURE_ON_EXCEPTION(isolate, 234 RETURN_FAILURE_ON_EXCEPTION(isolate,
245 JSObject::DefinePropertyOrElementIgnoreAttributes( 235 JSObject::DefinePropertyOrElementIgnoreAttributes(
246 object, name, function, DONT_ENUM)); 236 object, name, function, DONT_ENUM));
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after
558 Handle<Object> result; 548 Handle<Object> result;
559 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( 549 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
560 isolate, result, 550 isolate, result,
561 Execution::Call(isolate, reflect, isolate->factory()->undefined_value(), 551 Execution::Call(isolate, reflect, isolate->factory()->undefined_value(),
562 arraysize(argv), argv)); 552 arraysize(argv), argv));
563 553
564 return *result; 554 return *result;
565 } 555 }
566 } // namespace internal 556 } // namespace internal
567 } // namespace v8 557 } // namespace v8
OLDNEW
« no previous file with comments | « src/runtime/runtime.h ('k') | test/mjsunit/strong/class-object-frozen.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698