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

Unified Diff: src/v8natives.js

Issue 2944016: Add ES5 Object.freeze and Object.isFrozen methods.... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | test/es5conform/es5conform.status » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/v8natives.js
===================================================================
--- src/v8natives.js (revision 5046)
+++ src/v8natives.js (working copy)
@@ -723,7 +723,7 @@
// ES5 section 15.2.3.7.
function ObjectDefineProperties(obj, properties) {
- if ((!IS_SPEC_OBJECT_OR_NULL(obj) || IS_NULL_OR_UNDEFINED(obj)) &&
+ if ((!IS_SPEC_OBJECT_OR_NULL(obj) || IS_NULL_OR_UNDEFINED(obj)) &&
!IS_UNDETECTABLE(obj))
throw MakeTypeError("obj_ctor_property_non_object", ["defineProperties"]);
var props = ToObject(properties);
@@ -745,6 +745,24 @@
}
+// ES5 section 15.2.3.9.
+function ObjectFreeze(obj) {
+ if ((!IS_SPEC_OBJECT_OR_NULL(obj) || IS_NULL_OR_UNDEFINED(obj)) &&
+ !IS_UNDETECTABLE(obj)) {
+ throw MakeTypeError("obj_ctor_property_non_object", ["freeze"]);
+ }
+ var names = ObjectGetOwnPropertyNames(obj);
+ for (var key in names) {
+ var name = names[key];
+ var desc = GetOwnProperty(obj, name);
+ if (IsDataDescriptor(desc)) desc.setWritable(false);
+ if (desc.isConfigurable()) desc.setConfigurable(false);
+ DefineOwnProperty(obj, name, desc, true);
+ }
+ ObjectPreventExtension(obj);
+}
+
+
// ES5 section 15.2.3.10
function ObjectPreventExtension(obj) {
if ((!IS_SPEC_OBJECT_OR_NULL(obj) || IS_NULL_OR_UNDEFINED(obj)) &&
@@ -756,6 +774,26 @@
}
+// ES5 section 15.2.3.12
+function ObjectIsFrozen(obj) {
+ if ((!IS_SPEC_OBJECT_OR_NULL(obj) || IS_NULL_OR_UNDEFINED(obj)) &&
+ !IS_UNDETECTABLE(obj)) {
+ throw MakeTypeError("obj_ctor_property_non_object", ["isFrozen"]);
+ }
+ var names = ObjectGetOwnPropertyNames(obj);
+ for (var key in names) {
+ var name = names[key];
+ var desc = GetOwnProperty(obj, name);
+ if (IsDataDescriptor(desc) && desc.writable) return false;
+ if (desc.configurable) return false;
+ }
+ if (!ObjectIsExtensible(obj)) {
+ return true;
+ }
+ return false;
+}
+
+
// ES5 section 15.2.3.13
function ObjectIsExtensible(obj) {
if ((!IS_SPEC_OBJECT_OR_NULL(obj) || IS_NULL_OR_UNDEFINED(obj)) &&
@@ -799,10 +837,12 @@
"create", ObjectCreate,
"defineProperty", ObjectDefineProperty,
"defineProperties", ObjectDefineProperties,
+ "freeze", ObjectFreeze,
"getPrototypeOf", ObjectGetPrototypeOf,
"getOwnPropertyDescriptor", ObjectGetOwnPropertyDescriptor,
"getOwnPropertyNames", ObjectGetOwnPropertyNames,
"isExtensible", ObjectIsExtensible,
+ "isFrozen", ObjectIsFrozen,
"preventExtensions", ObjectPreventExtension
));
}
« no previous file with comments | « no previous file | test/es5conform/es5conform.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698