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

Unified Diff: src/v8natives.js

Issue 12422019: ES6 symbols: prevent reflection and proxy APIs from leaking symbols (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Deal with Object.observe as well Created 7 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/runtime.cc ('k') | test/cctest/test-api.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/v8natives.js
diff --git a/src/v8natives.js b/src/v8natives.js
index a382350f242c3c4375bbf82f3f8ee4d47115219c..3d237e20e7810ade8793f993c691130f14355894 100644
--- a/src/v8natives.js
+++ b/src/v8natives.js
@@ -256,6 +256,9 @@ function ObjectValueOf() {
// ECMA-262 - 15.2.4.5
function ObjectHasOwnProperty(V) {
if (%IsJSProxy(this)) {
+ // TODO(rossberg): adjust once there is a story for symbols vs proxies.
+ if (IS_SYMBOL(V)) return false;
+
var handler = %GetHandler(this);
return CallTrap1(handler, "hasOwn", DerivedHasOwnTrap, ToName(V));
}
@@ -278,6 +281,9 @@ function ObjectIsPrototypeOf(V) {
function ObjectPropertyIsEnumerable(V) {
var P = ToName(V);
if (%IsJSProxy(this)) {
+ // TODO(rossberg): adjust once there is a story for symbols vs proxies.
+ if (IS_SYMBOL(V)) return false;
+
var desc = GetOwnProperty(this, P);
return IS_UNDEFINED(desc) ? false : desc.isEnumerable();
}
@@ -645,6 +651,9 @@ function CallTrap2(handler, name, defaultTrap, x, y) {
function GetOwnProperty(obj, v) {
var p = ToName(v);
if (%IsJSProxy(obj)) {
+ // TODO(rossberg): adjust once there is a story for symbols vs proxies.
+ if (IS_SYMBOL(v)) return void 0;
+
var handler = %GetHandler(obj);
var descriptor = CallTrap1(handler, "getOwnPropertyDescriptor", void 0, p);
if (IS_UNDEFINED(descriptor)) return descriptor;
@@ -685,6 +694,9 @@ function Delete(obj, p, should_throw) {
// Harmony proxies.
function DefineProxyProperty(obj, p, attributes, should_throw) {
+ // TODO(rossberg): adjust once there is a story for symbols vs proxies.
+ if (IS_SYMBOL(p)) return false;
+
var handler = %GetHandler(obj);
var result = CallTrap2(handler, "defineProperty", void 0, p, attributes);
if (!ToBoolean(result)) {
@@ -950,6 +962,9 @@ function DefineArrayProperty(obj, p, desc, should_throw) {
// ES5 section 8.12.9, ES5 section 15.4.5.1 and Harmony proxies.
function DefineOwnProperty(obj, p, desc, should_throw) {
if (%IsJSProxy(obj)) {
+ // TODO(rossberg): adjust once there is a story for symbols vs proxies.
+ if (IS_SYMBOL(p)) return false;
+
var attributes = FromGenericPropertyDescriptor(desc);
return DefineProxyProperty(obj, p, attributes, should_throw);
} else if (IS_ARRAY(obj)) {
@@ -987,16 +1002,20 @@ function ToNameArray(obj, trap, includeSymbols) {
}
var n = ToUint32(obj.length);
var array = new $Array(n);
+ var realLength = 0;
var names = { __proto__: null }; // TODO(rossberg): use sets once ready.
for (var index = 0; index < n; index++) {
var s = ToName(obj[index]);
+ // TODO(rossberg): adjust once there is a story for symbols vs proxies.
if (IS_SYMBOL(s) && !includeSymbols) continue;
if (%HasLocalProperty(names, s)) {
throw MakeTypeError("proxy_repeated_prop_name", [obj, trap, s]);
}
array[index] = s;
+ ++realLength;
names[s] = 0;
}
+ array.length = realLength;
return array;
}
@@ -1010,7 +1029,7 @@ function ObjectGetOwnPropertyNames(obj) {
if (%IsJSProxy(obj)) {
var handler = %GetHandler(obj);
var names = CallTrap0(handler, "getOwnPropertyNames", void 0);
- return ToNameArray(names, "getOwnPropertyNames", true);
+ return ToNameArray(names, "getOwnPropertyNames", false);
}
var nameArrays = new InternalArray();
@@ -1036,7 +1055,7 @@ function ObjectGetOwnPropertyNames(obj) {
// Find all the named properties.
// Get the local property names.
- nameArrays.push(%GetLocalPropertyNames(obj));
+ nameArrays.push(%GetLocalPropertyNames(obj, false));
// Get names for named interceptor properties if any.
if ((interceptorInfo & 2) != 0) {
@@ -1056,7 +1075,8 @@ function ObjectGetOwnPropertyNames(obj) {
var propertySet = { __proto__: null };
var j = 0;
for (var i = 0; i < propertyNames.length; ++i) {
- var name = ToName(propertyNames[i]);
+ if (IS_SYMBOL(propertyNames[i])) continue;
+ var name = ToString(propertyNames[i]);
// We need to check for the exact property value since for intrinsic
// properties like toString if(propertySet["toString"]) will always
// succeed.
« no previous file with comments | « src/runtime.cc ('k') | test/cctest/test-api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698