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

Side by Side Diff: src/runtime.cc

Issue 359413007: Improve error reporting for duplicate object template properties. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 5 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
« no previous file with comments | « src/runtime.h ('k') | test/mjsunit/runtime-gen/addpropertyfortemplate.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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 <stdlib.h> 5 #include <stdlib.h>
6 #include <limits> 6 #include <limits>
7 7
8 #include "src/v8.h" 8 #include "src/v8.h"
9 9
10 #include "src/accessors.h" 10 #include "src/accessors.h"
(...skipping 5321 matching lines...) Expand 10 before | Expand all | Expand 10 after
5332 CONVERT_ARG_HANDLE_CHECKED(Object, key, 1); 5332 CONVERT_ARG_HANDLE_CHECKED(Object, key, 1);
5333 CONVERT_ARG_HANDLE_CHECKED(Object, value, 2); 5333 CONVERT_ARG_HANDLE_CHECKED(Object, value, 2);
5334 CONVERT_SMI_ARG_CHECKED(unchecked_attributes, 3); 5334 CONVERT_SMI_ARG_CHECKED(unchecked_attributes, 3);
5335 RUNTIME_ASSERT( 5335 RUNTIME_ASSERT(
5336 (unchecked_attributes & ~(READ_ONLY | DONT_ENUM | DONT_DELETE)) == 0); 5336 (unchecked_attributes & ~(READ_ONLY | DONT_ENUM | DONT_DELETE)) == 0);
5337 // Compute attributes. 5337 // Compute attributes.
5338 PropertyAttributes attributes = 5338 PropertyAttributes attributes =
5339 static_cast<PropertyAttributes>(unchecked_attributes); 5339 static_cast<PropertyAttributes>(unchecked_attributes);
5340 5340
5341 #ifdef DEBUG 5341 #ifdef DEBUG
5342 bool duplicate;
5342 if (key->IsName()) { 5343 if (key->IsName()) {
5343 LookupIterator it(object, Handle<Name>::cast(key), 5344 LookupIterator it(object, Handle<Name>::cast(key),
5344 LookupIterator::CHECK_OWN_REAL); 5345 LookupIterator::CHECK_OWN_REAL);
5345 JSReceiver::GetPropertyAttributes(&it); 5346 JSReceiver::GetPropertyAttributes(&it);
5346 RUNTIME_ASSERT(!it.IsFound()); 5347 duplicate = it.IsFound();
5347 } else { 5348 } else {
5348 uint32_t index = 0; 5349 uint32_t index = 0;
5349 RUNTIME_ASSERT(key->ToArrayIndex(&index)); 5350 RUNTIME_ASSERT(key->ToArrayIndex(&index));
5350 RUNTIME_ASSERT(!JSReceiver::HasOwnElement(object, index)); 5351 duplicate = JSReceiver::HasOwnElement(object, index);
5352 }
5353 RUNTIME_ASSERT(!duplicate);
5354 #endif
5355
5356 Handle<Object> result;
5357 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
5358 isolate, result,
5359 Runtime::DefineObjectProperty(object, key, value, attributes));
5360 return *result;
5361 }
5362
5363
5364 RUNTIME_FUNCTION(Runtime_AddPropertyForTemplate) {
5365 HandleScope scope(isolate);
5366 RUNTIME_ASSERT(args.length() == 4);
5367
5368 CONVERT_ARG_HANDLE_CHECKED(JSObject, object, 0);
5369 CONVERT_ARG_HANDLE_CHECKED(Object, key, 1);
5370 CONVERT_ARG_HANDLE_CHECKED(Object, value, 2);
5371 CONVERT_SMI_ARG_CHECKED(unchecked_attributes, 3);
5372 RUNTIME_ASSERT(
5373 (unchecked_attributes & ~(READ_ONLY | DONT_ENUM | DONT_DELETE)) == 0);
5374 // Compute attributes.
5375 PropertyAttributes attributes =
5376 static_cast<PropertyAttributes>(unchecked_attributes);
5377
5378 #ifdef DEBUG
5379 bool duplicate;
5380 if (key->IsName()) {
5381 LookupIterator it(object, Handle<Name>::cast(key),
5382 LookupIterator::CHECK_OWN_REAL);
5383 JSReceiver::GetPropertyAttributes(&it);
5384 duplicate = it.IsFound();
5385 } else {
5386 uint32_t index = 0;
5387 RUNTIME_ASSERT(key->ToArrayIndex(&index));
5388 duplicate = JSReceiver::HasOwnElement(object, index);
5389 }
5390 if (duplicate) {
5391 Handle<Object> args[1] = { key };
5392 Handle<Object> error = isolate->factory()->NewTypeError(
5393 "duplicate_template_property", HandleVector(args, 1));
5394 return isolate->Throw(*error);
5351 } 5395 }
5352 #endif 5396 #endif
5353 5397
5354 Handle<Object> result; 5398 Handle<Object> result;
5355 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( 5399 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
5356 isolate, result, 5400 isolate, result,
5357 Runtime::DefineObjectProperty(object, key, value, attributes)); 5401 Runtime::DefineObjectProperty(object, key, value, attributes));
5358 return *result; 5402 return *result;
5359 } 5403 }
5360 5404
(...skipping 9718 matching lines...) Expand 10 before | Expand all | Expand 10 after
15079 } 15123 }
15080 return NULL; 15124 return NULL;
15081 } 15125 }
15082 15126
15083 15127
15084 const Runtime::Function* Runtime::FunctionForId(Runtime::FunctionId id) { 15128 const Runtime::Function* Runtime::FunctionForId(Runtime::FunctionId id) {
15085 return &(kIntrinsicFunctions[static_cast<int>(id)]); 15129 return &(kIntrinsicFunctions[static_cast<int>(id)]);
15086 } 15130 }
15087 15131
15088 } } // namespace v8::internal 15132 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/runtime.h ('k') | test/mjsunit/runtime-gen/addpropertyfortemplate.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698