OLD | NEW |
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 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 if (super_class->IsJSFunction() && | 97 if (super_class->IsJSFunction() && |
98 Handle<JSFunction>::cast(super_class)->shared()->is_generator()) { | 98 Handle<JSFunction>::cast(super_class)->shared()->is_generator()) { |
99 THROW_NEW_ERROR( | 99 THROW_NEW_ERROR( |
100 isolate, | 100 isolate, |
101 NewTypeError(MessageTemplate::kExtendsValueGenerator, super_class), | 101 NewTypeError(MessageTemplate::kExtendsValueGenerator, super_class), |
102 Object); | 102 Object); |
103 } | 103 } |
104 ASSIGN_RETURN_ON_EXCEPTION( | 104 ASSIGN_RETURN_ON_EXCEPTION( |
105 isolate, prototype_parent, | 105 isolate, prototype_parent, |
106 Runtime::GetObjectProperty(isolate, super_class, | 106 Runtime::GetObjectProperty(isolate, super_class, |
107 isolate->factory()->prototype_string(), | 107 isolate->factory()->prototype_string()), |
108 SLOPPY), | |
109 Object); | 108 Object); |
110 if (!prototype_parent->IsNull() && !prototype_parent->IsJSReceiver()) { | 109 if (!prototype_parent->IsNull() && !prototype_parent->IsJSReceiver()) { |
111 THROW_NEW_ERROR( | 110 THROW_NEW_ERROR( |
112 isolate, NewTypeError(MessageTemplate::kPrototypeParentNotAnObject, | 111 isolate, NewTypeError(MessageTemplate::kPrototypeParentNotAnObject, |
113 prototype_parent), | 112 prototype_parent), |
114 Object); | 113 Object); |
115 } | 114 } |
116 constructor_parent = super_class; | 115 constructor_parent = super_class; |
117 } else { | 116 } else { |
118 THROW_NEW_ERROR( | 117 THROW_NEW_ERROR( |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 MAYBE_RETURN(JSReceiver::SetIntegrityLevel(prototype, FROZEN, | 215 MAYBE_RETURN(JSReceiver::SetIntegrityLevel(prototype, FROZEN, |
217 Object::THROW_ON_ERROR), | 216 Object::THROW_ON_ERROR), |
218 isolate->heap()->exception()); | 217 isolate->heap()->exception()); |
219 MAYBE_RETURN(JSReceiver::SetIntegrityLevel(constructor, FROZEN, | 218 MAYBE_RETURN(JSReceiver::SetIntegrityLevel(constructor, FROZEN, |
220 Object::THROW_ON_ERROR), | 219 Object::THROW_ON_ERROR), |
221 isolate->heap()->exception()); | 220 isolate->heap()->exception()); |
222 } | 221 } |
223 return *constructor; | 222 return *constructor; |
224 } | 223 } |
225 | 224 |
226 | |
227 static MaybeHandle<Object> LoadFromSuper(Isolate* isolate, | 225 static MaybeHandle<Object> LoadFromSuper(Isolate* isolate, |
228 Handle<Object> receiver, | 226 Handle<Object> receiver, |
229 Handle<JSObject> home_object, | 227 Handle<JSObject> home_object, |
230 Handle<Name> name, | 228 Handle<Name> name) { |
231 LanguageMode language_mode) { | |
232 if (home_object->IsAccessCheckNeeded() && | 229 if (home_object->IsAccessCheckNeeded() && |
233 !isolate->MayAccess(handle(isolate->context()), home_object)) { | 230 !isolate->MayAccess(handle(isolate->context()), home_object)) { |
234 isolate->ReportFailedAccessCheck(home_object); | 231 isolate->ReportFailedAccessCheck(home_object); |
235 RETURN_EXCEPTION_IF_SCHEDULED_EXCEPTION(isolate, Object); | 232 RETURN_EXCEPTION_IF_SCHEDULED_EXCEPTION(isolate, Object); |
236 } | 233 } |
237 | 234 |
238 PrototypeIterator iter(isolate, home_object); | 235 PrototypeIterator iter(isolate, home_object); |
239 Handle<Object> proto = PrototypeIterator::GetCurrent(iter); | 236 Handle<Object> proto = PrototypeIterator::GetCurrent(iter); |
240 if (!proto->IsJSReceiver()) { | 237 if (!proto->IsJSReceiver()) { |
241 return Object::ReadAbsentProperty(isolate, proto, name, language_mode); | 238 return Object::ReadAbsentProperty(isolate, proto, name); |
242 } | 239 } |
243 | 240 |
244 LookupIterator it(receiver, name, Handle<JSReceiver>::cast(proto)); | 241 LookupIterator it(receiver, name, Handle<JSReceiver>::cast(proto)); |
245 Handle<Object> result; | 242 Handle<Object> result; |
246 ASSIGN_RETURN_ON_EXCEPTION(isolate, result, | 243 ASSIGN_RETURN_ON_EXCEPTION(isolate, result, Object::GetProperty(&it), Object); |
247 Object::GetProperty(&it, language_mode), Object); | |
248 return result; | 244 return result; |
249 } | 245 } |
250 | 246 |
251 | |
252 static MaybeHandle<Object> LoadElementFromSuper(Isolate* isolate, | 247 static MaybeHandle<Object> LoadElementFromSuper(Isolate* isolate, |
253 Handle<Object> receiver, | 248 Handle<Object> receiver, |
254 Handle<JSObject> home_object, | 249 Handle<JSObject> home_object, |
255 uint32_t index, | 250 uint32_t index) { |
256 LanguageMode language_mode) { | |
257 if (home_object->IsAccessCheckNeeded() && | 251 if (home_object->IsAccessCheckNeeded() && |
258 !isolate->MayAccess(handle(isolate->context()), home_object)) { | 252 !isolate->MayAccess(handle(isolate->context()), home_object)) { |
259 isolate->ReportFailedAccessCheck(home_object); | 253 isolate->ReportFailedAccessCheck(home_object); |
260 RETURN_EXCEPTION_IF_SCHEDULED_EXCEPTION(isolate, Object); | 254 RETURN_EXCEPTION_IF_SCHEDULED_EXCEPTION(isolate, Object); |
261 } | 255 } |
262 | 256 |
263 PrototypeIterator iter(isolate, home_object); | 257 PrototypeIterator iter(isolate, home_object); |
264 Handle<Object> proto = PrototypeIterator::GetCurrent(iter); | 258 Handle<Object> proto = PrototypeIterator::GetCurrent(iter); |
265 if (!proto->IsJSReceiver()) { | 259 if (!proto->IsJSReceiver()) { |
266 Handle<Object> name = isolate->factory()->NewNumberFromUint(index); | 260 Handle<Object> name = isolate->factory()->NewNumberFromUint(index); |
267 return Object::ReadAbsentProperty(isolate, proto, name, language_mode); | 261 return Object::ReadAbsentProperty(isolate, proto, name); |
268 } | 262 } |
269 | 263 |
270 LookupIterator it(isolate, receiver, index, Handle<JSReceiver>::cast(proto)); | 264 LookupIterator it(isolate, receiver, index, Handle<JSReceiver>::cast(proto)); |
271 Handle<Object> result; | 265 Handle<Object> result; |
272 ASSIGN_RETURN_ON_EXCEPTION(isolate, result, | 266 ASSIGN_RETURN_ON_EXCEPTION(isolate, result, Object::GetProperty(&it), Object); |
273 Object::GetProperty(&it, language_mode), Object); | |
274 return result; | 267 return result; |
275 } | 268 } |
276 | 269 |
277 | 270 |
278 // TODO(conradw): It would be more efficient to have a separate runtime function | |
279 // for strong mode. | |
280 RUNTIME_FUNCTION(Runtime_LoadFromSuper) { | 271 RUNTIME_FUNCTION(Runtime_LoadFromSuper) { |
281 HandleScope scope(isolate); | 272 HandleScope scope(isolate); |
282 DCHECK(args.length() == 4); | 273 DCHECK_EQ(3, args.length()); |
283 CONVERT_ARG_HANDLE_CHECKED(Object, receiver, 0); | 274 CONVERT_ARG_HANDLE_CHECKED(Object, receiver, 0); |
284 CONVERT_ARG_HANDLE_CHECKED(JSObject, home_object, 1); | 275 CONVERT_ARG_HANDLE_CHECKED(JSObject, home_object, 1); |
285 CONVERT_ARG_HANDLE_CHECKED(Name, name, 2); | 276 CONVERT_ARG_HANDLE_CHECKED(Name, name, 2); |
286 CONVERT_LANGUAGE_MODE_ARG_CHECKED(language_mode, 3); | |
287 | 277 |
288 Handle<Object> result; | 278 Handle<Object> result; |
289 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 279 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
290 isolate, result, | 280 isolate, result, LoadFromSuper(isolate, receiver, home_object, name)); |
291 LoadFromSuper(isolate, receiver, home_object, name, language_mode)); | |
292 return *result; | 281 return *result; |
293 } | 282 } |
294 | 283 |
295 | 284 |
296 RUNTIME_FUNCTION(Runtime_LoadKeyedFromSuper) { | 285 RUNTIME_FUNCTION(Runtime_LoadKeyedFromSuper) { |
297 HandleScope scope(isolate); | 286 HandleScope scope(isolate); |
298 DCHECK(args.length() == 4); | 287 DCHECK_EQ(3, args.length()); |
299 CONVERT_ARG_HANDLE_CHECKED(Object, receiver, 0); | 288 CONVERT_ARG_HANDLE_CHECKED(Object, receiver, 0); |
300 CONVERT_ARG_HANDLE_CHECKED(JSObject, home_object, 1); | 289 CONVERT_ARG_HANDLE_CHECKED(JSObject, home_object, 1); |
301 CONVERT_ARG_HANDLE_CHECKED(Object, key, 2); | 290 CONVERT_ARG_HANDLE_CHECKED(Object, key, 2); |
302 CONVERT_LANGUAGE_MODE_ARG_CHECKED(language_mode, 3); | |
303 | 291 |
304 uint32_t index = 0; | 292 uint32_t index = 0; |
305 Handle<Object> result; | 293 Handle<Object> result; |
306 | 294 |
307 if (key->ToArrayIndex(&index)) { | 295 if (key->ToArrayIndex(&index)) { |
308 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 296 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
309 isolate, result, LoadElementFromSuper(isolate, receiver, home_object, | 297 isolate, result, |
310 index, language_mode)); | 298 LoadElementFromSuper(isolate, receiver, home_object, index)); |
311 return *result; | 299 return *result; |
312 } | 300 } |
313 | 301 |
314 Handle<Name> name; | 302 Handle<Name> name; |
315 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, name, | 303 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, name, |
316 Object::ToName(isolate, key)); | 304 Object::ToName(isolate, key)); |
317 // TODO(verwaest): Unify using LookupIterator. | 305 // TODO(verwaest): Unify using LookupIterator. |
318 if (name->AsArrayIndex(&index)) { | 306 if (name->AsArrayIndex(&index)) { |
319 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 307 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
320 isolate, result, LoadElementFromSuper(isolate, receiver, home_object, | 308 isolate, result, |
321 index, language_mode)); | 309 LoadElementFromSuper(isolate, receiver, home_object, index)); |
322 return *result; | 310 return *result; |
323 } | 311 } |
324 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 312 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
325 isolate, result, | 313 isolate, result, LoadFromSuper(isolate, receiver, home_object, name)); |
326 LoadFromSuper(isolate, receiver, home_object, name, language_mode)); | |
327 return *result; | 314 return *result; |
328 } | 315 } |
329 | 316 |
330 | 317 |
331 static Object* StoreToSuper(Isolate* isolate, Handle<JSObject> home_object, | 318 static Object* StoreToSuper(Isolate* isolate, Handle<JSObject> home_object, |
332 Handle<Object> receiver, Handle<Name> name, | 319 Handle<Object> receiver, Handle<Name> name, |
333 Handle<Object> value, LanguageMode language_mode) { | 320 Handle<Object> value, LanguageMode language_mode) { |
334 if (home_object->IsAccessCheckNeeded() && | 321 if (home_object->IsAccessCheckNeeded() && |
335 !isolate->MayAccess(handle(isolate->context()), home_object)) { | 322 !isolate->MayAccess(handle(isolate->context()), home_object)) { |
336 isolate->ReportFailedAccessCheck(home_object); | 323 isolate->ReportFailedAccessCheck(home_object); |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
445 | 432 |
446 RUNTIME_FUNCTION(Runtime_GetSuperConstructor) { | 433 RUNTIME_FUNCTION(Runtime_GetSuperConstructor) { |
447 SealHandleScope shs(isolate); | 434 SealHandleScope shs(isolate); |
448 DCHECK_EQ(1, args.length()); | 435 DCHECK_EQ(1, args.length()); |
449 CONVERT_ARG_CHECKED(JSFunction, active_function, 0); | 436 CONVERT_ARG_CHECKED(JSFunction, active_function, 0); |
450 return active_function->map()->prototype(); | 437 return active_function->map()->prototype(); |
451 } | 438 } |
452 | 439 |
453 } // namespace internal | 440 } // namespace internal |
454 } // namespace v8 | 441 } // namespace v8 |
OLD | NEW |