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

Side by Side Diff: src/objects.cc

Issue 1558433002: [runtime] Migrate Object.create to C++. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Address Camillos comment. Created 4 years, 11 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/objects.h ('k') | src/runtime/runtime-object.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 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 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/objects.h" 5 #include "src/objects.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 #include <iomanip> 8 #include <iomanip>
9 #include <sstream> 9 #include <sstream>
10 10
(...skipping 6267 matching lines...) Expand 10 before | Expand all | Expand 10 after
6278 // 7. ReturnIfAbrupt(success). 6278 // 7. ReturnIfAbrupt(success).
6279 MAYBE_RETURN(success, isolate->heap()->exception()); 6279 MAYBE_RETURN(success, isolate->heap()->exception());
6280 CHECK(success.FromJust()); 6280 CHECK(success.FromJust());
6281 // 8. Return O. 6281 // 8. Return O.
6282 return *object; 6282 return *object;
6283 } 6283 }
6284 6284
6285 6285
6286 // ES6 19.1.2.3.1 6286 // ES6 19.1.2.3.1
6287 // static 6287 // static
6288 Object* JSReceiver::DefineProperties(Isolate* isolate, Handle<Object> object, 6288 MaybeHandle<Object> JSReceiver::DefineProperties(Isolate* isolate,
6289 Handle<Object> properties) { 6289 Handle<Object> object,
6290 Handle<Object> properties) {
6290 // 1. If Type(O) is not Object, throw a TypeError exception. 6291 // 1. If Type(O) is not Object, throw a TypeError exception.
6291 if (!object->IsJSReceiver()) { 6292 if (!object->IsJSReceiver()) {
6292 Handle<String> fun_name = 6293 Handle<String> fun_name =
6293 isolate->factory()->InternalizeUtf8String("Object.defineProperties"); 6294 isolate->factory()->InternalizeUtf8String("Object.defineProperties");
6294 THROW_NEW_ERROR_RETURN_FAILURE( 6295 THROW_NEW_ERROR(isolate,
6295 isolate, NewTypeError(MessageTemplate::kCalledOnNonObject, fun_name)); 6296 NewTypeError(MessageTemplate::kCalledOnNonObject, fun_name),
6297 Object);
6296 } 6298 }
6297 // 2. Let props be ToObject(Properties). 6299 // 2. Let props be ToObject(Properties).
6298 // 3. ReturnIfAbrupt(props). 6300 // 3. ReturnIfAbrupt(props).
6299 Handle<JSReceiver> props; 6301 Handle<JSReceiver> props;
6300 if (!Object::ToObject(isolate, properties).ToHandle(&props)) { 6302 if (!Object::ToObject(isolate, properties).ToHandle(&props)) {
6301 THROW_NEW_ERROR_RETURN_FAILURE( 6303 THROW_NEW_ERROR(isolate,
6302 isolate, NewTypeError(MessageTemplate::kUndefinedOrNullToObject)); 6304 NewTypeError(MessageTemplate::kUndefinedOrNullToObject),
6305 Object);
6303 } 6306 }
6304 // 4. Let keys be props.[[OwnPropertyKeys]](). 6307 // 4. Let keys be props.[[OwnPropertyKeys]]().
6305 // 5. ReturnIfAbrupt(keys). 6308 // 5. ReturnIfAbrupt(keys).
6306 Handle<FixedArray> keys; 6309 Handle<FixedArray> keys;
6307 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( 6310 ASSIGN_RETURN_ON_EXCEPTION(
6308 isolate, keys, 6311 isolate, keys,
6309 JSReceiver::GetKeys(props, JSReceiver::OWN_ONLY, ALL_PROPERTIES)); 6312 JSReceiver::GetKeys(props, JSReceiver::OWN_ONLY, ALL_PROPERTIES), Object);
6310 // 6. Let descriptors be an empty List. 6313 // 6. Let descriptors be an empty List.
6311 int capacity = keys->length(); 6314 int capacity = keys->length();
6312 std::vector<PropertyDescriptor> descriptors(capacity); 6315 std::vector<PropertyDescriptor> descriptors(capacity);
6313 size_t descriptors_index = 0; 6316 size_t descriptors_index = 0;
6314 // 7. Repeat for each element nextKey of keys in List order, 6317 // 7. Repeat for each element nextKey of keys in List order,
6315 for (int i = 0; i < keys->length(); ++i) { 6318 for (int i = 0; i < keys->length(); ++i) {
6316 Handle<Object> next_key(keys->get(i), isolate); 6319 Handle<Object> next_key(keys->get(i), isolate);
6317 // 7a. Let propDesc be props.[[GetOwnProperty]](nextKey). 6320 // 7a. Let propDesc be props.[[GetOwnProperty]](nextKey).
6318 // 7b. ReturnIfAbrupt(propDesc). 6321 // 7b. ReturnIfAbrupt(propDesc).
6319 bool success = false; 6322 bool success = false;
6320 LookupIterator it = LookupIterator::PropertyOrElement( 6323 LookupIterator it = LookupIterator::PropertyOrElement(
6321 isolate, props, next_key, &success, LookupIterator::HIDDEN); 6324 isolate, props, next_key, &success, LookupIterator::HIDDEN);
6322 DCHECK(success); 6325 DCHECK(success);
6323 Maybe<PropertyAttributes> maybe = JSReceiver::GetPropertyAttributes(&it); 6326 Maybe<PropertyAttributes> maybe = JSReceiver::GetPropertyAttributes(&it);
6324 if (!maybe.IsJust()) return isolate->heap()->exception(); 6327 if (!maybe.IsJust()) return MaybeHandle<Object>();
6325 PropertyAttributes attrs = maybe.FromJust(); 6328 PropertyAttributes attrs = maybe.FromJust();
6326 // 7c. If propDesc is not undefined and propDesc.[[Enumerable]] is true: 6329 // 7c. If propDesc is not undefined and propDesc.[[Enumerable]] is true:
6327 if (attrs == ABSENT) continue; 6330 if (attrs == ABSENT) continue;
6328 if (attrs & DONT_ENUM) continue; 6331 if (attrs & DONT_ENUM) continue;
6329 // 7c i. Let descObj be Get(props, nextKey). 6332 // 7c i. Let descObj be Get(props, nextKey).
6330 // 7c ii. ReturnIfAbrupt(descObj). 6333 // 7c ii. ReturnIfAbrupt(descObj).
6331 Handle<Object> desc_obj; 6334 Handle<Object> desc_obj;
6332 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, desc_obj, 6335 ASSIGN_RETURN_ON_EXCEPTION(isolate, desc_obj, Object::GetProperty(&it),
6333 Object::GetProperty(&it)); 6336 Object);
6334 // 7c iii. Let desc be ToPropertyDescriptor(descObj). 6337 // 7c iii. Let desc be ToPropertyDescriptor(descObj).
6335 success = PropertyDescriptor::ToPropertyDescriptor( 6338 success = PropertyDescriptor::ToPropertyDescriptor(
6336 isolate, desc_obj, &descriptors[descriptors_index]); 6339 isolate, desc_obj, &descriptors[descriptors_index]);
6337 // 7c iv. ReturnIfAbrupt(desc). 6340 // 7c iv. ReturnIfAbrupt(desc).
6338 if (!success) return isolate->heap()->exception(); 6341 if (!success) return MaybeHandle<Object>();
6339 // 7c v. Append the pair (a two element List) consisting of nextKey and 6342 // 7c v. Append the pair (a two element List) consisting of nextKey and
6340 // desc to the end of descriptors. 6343 // desc to the end of descriptors.
6341 descriptors[descriptors_index].set_name(next_key); 6344 descriptors[descriptors_index].set_name(next_key);
6342 descriptors_index++; 6345 descriptors_index++;
6343 } 6346 }
6344 // 8. For each pair from descriptors in list order, 6347 // 8. For each pair from descriptors in list order,
6345 for (size_t i = 0; i < descriptors_index; ++i) { 6348 for (size_t i = 0; i < descriptors_index; ++i) {
6346 PropertyDescriptor* desc = &descriptors[i]; 6349 PropertyDescriptor* desc = &descriptors[i];
6347 // 8a. Let P be the first element of pair. 6350 // 8a. Let P be the first element of pair.
6348 // 8b. Let desc be the second element of pair. 6351 // 8b. Let desc be the second element of pair.
6349 // 8c. Let status be DefinePropertyOrThrow(O, P, desc). 6352 // 8c. Let status be DefinePropertyOrThrow(O, P, desc).
6350 Maybe<bool> status = 6353 Maybe<bool> status =
6351 DefineOwnProperty(isolate, Handle<JSReceiver>::cast(object), 6354 DefineOwnProperty(isolate, Handle<JSReceiver>::cast(object),
6352 desc->name(), desc, THROW_ON_ERROR); 6355 desc->name(), desc, THROW_ON_ERROR);
6353 // 8d. ReturnIfAbrupt(status). 6356 // 8d. ReturnIfAbrupt(status).
6354 MAYBE_RETURN(status, isolate->heap()->exception()); 6357 if (!status.IsJust()) return MaybeHandle<Object>();
6355 CHECK(status.FromJust()); 6358 CHECK(status.FromJust());
6356 } 6359 }
6357 // 9. Return o. 6360 // 9. Return o.
6358 return *object; 6361 return object;
6359 } 6362 }
6360 6363
6361 6364
6362 // static 6365 // static
6363 Maybe<bool> JSReceiver::DefineOwnProperty(Isolate* isolate, 6366 Maybe<bool> JSReceiver::DefineOwnProperty(Isolate* isolate,
6364 Handle<JSReceiver> object, 6367 Handle<JSReceiver> object,
6365 Handle<Object> key, 6368 Handle<Object> key,
6366 PropertyDescriptor* desc, 6369 PropertyDescriptor* desc,
6367 ShouldThrow should_throw) { 6370 ShouldThrow should_throw) {
6368 if (object->IsJSArray()) { 6371 if (object->IsJSArray()) {
(...skipping 13121 matching lines...) Expand 10 before | Expand all | Expand 10 after
19490 if (cell->value() != *new_value) { 19493 if (cell->value() != *new_value) {
19491 cell->set_value(*new_value); 19494 cell->set_value(*new_value);
19492 Isolate* isolate = cell->GetIsolate(); 19495 Isolate* isolate = cell->GetIsolate();
19493 cell->dependent_code()->DeoptimizeDependentCodeGroup( 19496 cell->dependent_code()->DeoptimizeDependentCodeGroup(
19494 isolate, DependentCode::kPropertyCellChangedGroup); 19497 isolate, DependentCode::kPropertyCellChangedGroup);
19495 } 19498 }
19496 } 19499 }
19497 19500
19498 } // namespace internal 19501 } // namespace internal
19499 } // namespace v8 19502 } // namespace v8
OLDNEW
« no previous file with comments | « src/objects.h ('k') | src/runtime/runtime-object.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698