Reviewers: Yang,
Message:
PTAL
Description:
Improve error reporting for duplicate object template properties.
BUG=
Please review this at https://codereview.chromium.org/359413007/
SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge
Affected files (+53, -7 lines):
M src/apinatives.js
M src/messages.js
M src/runtime.h
M src/runtime.cc
A + test/mjsunit/runtime-gen/addpropertyfortemplate.js
M tools/generate-runtime-tests.py
Index: src/apinatives.js
diff --git a/src/apinatives.js b/src/apinatives.js
index
50c753ec70e517aa38b1de60b5d6e02bf3e65b73..0ba5c6838db004f06dde4961470964734f346ad9
100644
--- a/src/apinatives.js
+++ b/src/apinatives.js
@@ -99,7 +99,7 @@ function ConfigureTemplateInstance(obj, data) {
var prop_data = properties[i + 2];
var attributes = properties[i + 3];
var value = Instantiate(prop_data, name);
- %AddProperty(obj, name, value, attributes);
+ %AddPropertyForTemplate(obj, name, value, attributes);
} else if (length == 4 || length == 5) {
// TODO(verwaest): The 5th value used to be access_control. Remove
once
// the bindings are updated.
Index: src/messages.js
diff --git a/src/messages.js b/src/messages.js
index
8f83a62107ee93ecfd00967972cf7f6490b499c1..da373b2dd2d5a8c94e398a8d2d21c89c37f000a9
100644
--- a/src/messages.js
+++ b/src/messages.js
@@ -26,6 +26,7 @@ var kMessages = {
newline_after_throw: ["Illegal newline after throw"],
label_redeclaration: ["Label '", "%0", "' has already been
declared"],
var_redeclaration: ["Identifier '", "%0", "' has already
been declared"],
+ duplicate_template_property: ["Object template has duplicate
property '", "%0", "'"],
no_catch_or_finally: ["Missing catch or finally after try"],
unknown_label: ["Undefined label '", "%0", "'"],
uncaught_exception: ["Uncaught ", "%0"],
Index: src/runtime.cc
diff --git a/src/runtime.cc b/src/runtime.cc
index
888f665d21c8d8ab126a7d0ff9703d534094d5aa..1d10a8e222aecfa213e9a9ba1122e2a81494110b
100644
--- a/src/runtime.cc
+++ b/src/runtime.cc
@@ -5339,15 +5339,59 @@ RUNTIME_FUNCTION(Runtime_AddProperty) {
static_cast<PropertyAttributes>(unchecked_attributes);
#ifdef DEBUG
+ bool duplicate;
if (key->IsName()) {
LookupIterator it(object, Handle<Name>::cast(key),
LookupIterator::CHECK_OWN_REAL);
JSReceiver::GetPropertyAttributes(&it);
- RUNTIME_ASSERT(!it.IsFound());
+ duplicate = it.IsFound();
} else {
uint32_t index = 0;
RUNTIME_ASSERT(key->ToArrayIndex(&index));
- RUNTIME_ASSERT(!JSReceiver::HasOwnElement(object, index));
+ duplicate = JSReceiver::HasOwnElement(object, index);
+ }
+ RUNTIME_ASSERT(!duplicate);
+#endif
+
+ Handle<Object> result;
+ ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
+ isolate, result,
+ Runtime::DefineObjectProperty(object, key, value, attributes));
+ return *result;
+}
+
+
+RUNTIME_FUNCTION(Runtime_AddPropertyForTemplate) {
+ HandleScope scope(isolate);
+ RUNTIME_ASSERT(args.length() == 4);
+
+ CONVERT_ARG_HANDLE_CHECKED(JSObject, object, 0);
+ CONVERT_ARG_HANDLE_CHECKED(Object, key, 1);
+ CONVERT_ARG_HANDLE_CHECKED(Object, value, 2);
+ CONVERT_SMI_ARG_CHECKED(unchecked_attributes, 3);
+ RUNTIME_ASSERT(
+ (unchecked_attributes & ~(READ_ONLY | DONT_ENUM | DONT_DELETE)) ==
0);
+ // Compute attributes.
+ PropertyAttributes attributes =
+ static_cast<PropertyAttributes>(unchecked_attributes);
+
+#ifdef DEBUG
+ bool duplicate;
+ if (key->IsName()) {
+ LookupIterator it(object, Handle<Name>::cast(key),
+ LookupIterator::CHECK_OWN_REAL);
+ JSReceiver::GetPropertyAttributes(&it);
+ duplicate = it.IsFound();
+ } else {
+ uint32_t index = 0;
+ RUNTIME_ASSERT(key->ToArrayIndex(&index));
+ duplicate = JSReceiver::HasOwnElement(object, index);
+ }
+ if (duplicate) {
+ Handle<Object> args[1] = { key };
+ Handle<Object> error = isolate->factory()->NewTypeError(
+ "duplicate_template_property", HandleVector(args, 1));
+ return isolate->Throw(*error);
}
#endif
Index: src/runtime.h
diff --git a/src/runtime.h b/src/runtime.h
index
ebc8598c876fbef46420c4769c5e8750ea9edaeb..f4fe6f7d66833169a0b1ca1ca33473ef40368624
100644
--- a/src/runtime.h
+++ b/src/runtime.h
@@ -225,6 +225,7 @@ namespace internal {
F(IsAttachedGlobal, 1, 1) \
\
F(AddProperty, 4, 1) \
+ F(AddPropertyForTemplate, 4, 1) \
F(SetProperty, 4, 1) \
F(DefineDataPropertyUnchecked, 4, 1) \
F(DefineAccessorPropertyUnchecked, 5, 1) \
Index: test/mjsunit/runtime-gen/addpropertyfortemplate.js
diff --git a/test/mjsunit/runtime-gen/addproperty.js
b/test/mjsunit/runtime-gen/addpropertyfortemplate.js
similarity index 73%
copy from test/mjsunit/runtime-gen/addproperty.js
copy to test/mjsunit/runtime-gen/addpropertyfortemplate.js
index
48b985d094ed245ef53695341583cd6b197c250c..63df11648b7f097ecdd3065b825de7c3e5b8bb41
100644
--- a/test/mjsunit/runtime-gen/addproperty.js
+++ b/test/mjsunit/runtime-gen/addpropertyfortemplate.js
@@ -2,7 +2,7 @@
// AUTO-GENERATED BY tools/generate-runtime-tests.py, DO NOT MODIFY
// Flags: --allow-natives-syntax --harmony
var _object = new Object();
-var arg1 = 10;
+var _key = new Object();
var _value = new Object();
var _unchecked_attributes = 1;
-%AddProperty(_object, arg1, _value, _unchecked_attributes);
+%AddPropertyForTemplate(_object, _key, _value, _unchecked_attributes);
Index: tools/generate-runtime-tests.py
diff --git a/tools/generate-runtime-tests.py
b/tools/generate-runtime-tests.py
index
f018cf044471eb3eb46470cff3536b64d5e9335b..301ffebbecbb586cd61feaefb95a6b669b456d12
100755
--- a/tools/generate-runtime-tests.py
+++ b/tools/generate-runtime-tests.py
@@ -47,8 +47,8 @@ EXPAND_MACROS = [
# that the parser doesn't bit-rot. Change the values as needed when you
add,
# remove or change runtime functions, but make sure we don't lose our
ability
# to parse them!
-EXPECTED_FUNCTION_COUNT = 416
-EXPECTED_FUZZABLE_COUNT = 331
+EXPECTED_FUNCTION_COUNT = 417
+EXPECTED_FUZZABLE_COUNT = 332
EXPECTED_CCTEST_COUNT = 6
EXPECTED_UNKNOWN_COUNT = 4
EXPECTED_BUILTINS_COUNT = 809
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.