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

Unified Diff: src/string.js

Issue 6902104: Don't exchange null and undefined with the global object in function.prototype.{call, apply} for ... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 9 years, 8 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
Index: src/string.js
===================================================================
--- src/string.js (revision 7676)
+++ src/string.js (working copy)
@@ -62,6 +62,10 @@
// ECMA-262, section 15.5.4.4
function StringCharAt(pos) {
+ if (IS_NULL_OR_UNDEFINED(this)) {
+ throw MakeTypeError("obj_ctor_property_non_object", ["charAt"]);
+ }
+
var result = %_StringCharAt(this, pos);
if (%_IsSmi(result)) {
result = %_StringCharAt(TO_STRING_INLINE(this), TO_INTEGER(pos));
@@ -72,6 +76,10 @@
// ECMA-262 section 15.5.4.5
function StringCharCodeAt(pos) {
+ if (IS_NULL_OR_UNDEFINED(this)) {
+ throw MakeTypeError("obj_ctor_property_non_object", ["charCodeAt"]);
+ }
+
var result = %_StringCharCodeAt(this, pos);
if (!%_IsSmi(result)) {
result = %_StringCharCodeAt(TO_STRING_INLINE(this), TO_INTEGER(pos));
@@ -82,6 +90,9 @@
// ECMA-262, section 15.5.4.6
function StringConcat() {
+ if (IS_NULL_OR_UNDEFINED(this)) {
+ throw MakeTypeError("obj_ctor_property_non_object", ["concat"]);
+ }
var len = %_ArgumentsLength();
var this_as_string = TO_STRING_INLINE(this);
if (len === 1) {
@@ -102,6 +113,9 @@
// ECMA-262 section 15.5.4.7
function StringIndexOf(pattern /* position */) { // length == 1
+ if (IS_NULL_OR_UNDEFINED(this)) {
+ throw MakeTypeError("obj_ctor_property_non_object", ["indexOf"]);
+ }
var subject = TO_STRING_INLINE(this);
pattern = TO_STRING_INLINE(pattern);
var index = 0;
@@ -117,6 +131,9 @@
// ECMA-262 section 15.5.4.8
function StringLastIndexOf(pat /* position */) { // length == 1
+ if (IS_NULL_OR_UNDEFINED(this)) {
+ throw MakeTypeError("obj_ctor_property_non_object", ["lastIndexOf"]);
+ }
var sub = TO_STRING_INLINE(this);
var subLength = sub.length;
var pat = TO_STRING_INLINE(pat);
@@ -146,6 +163,9 @@
// This function is implementation specific. For now, we do not
// do anything locale specific.
function StringLocaleCompare(other) {
+ if (IS_NULL_OR_UNDEFINED(this)) {
+ throw MakeTypeError("obj_ctor_property_non_object", ["localeCompare"]);
+ }
if (%_ArgumentsLength() === 0) return 0;
return %StringLocaleCompare(TO_STRING_INLINE(this),
TO_STRING_INLINE(other));
@@ -154,6 +174,9 @@
// ECMA-262 section 15.5.4.10
function StringMatch(regexp) {
+ if (IS_NULL_OR_UNDEFINED(this)) {
+ throw MakeTypeError("obj_ctor_property_non_object", ["match"]);
+ }
var subject = TO_STRING_INLINE(this);
if (IS_REGEXP(regexp)) {
if (!regexp.global) return RegExpExecNoTests(regexp, subject, 0);
@@ -187,6 +210,9 @@
// ECMA-262, section 15.5.4.11
function StringReplace(search, replace) {
+ if (IS_NULL_OR_UNDEFINED(this)) {
+ throw MakeTypeError("obj_ctor_property_non_object", ["replace"]);
+ }
var subject = TO_STRING_INLINE(this);
// Delegate to one of the regular expression variants if necessary.
@@ -467,6 +493,9 @@
// ECMA-262 section 15.5.4.12
function StringSearch(re) {
+ if (IS_NULL_OR_UNDEFINED(this)) {
+ throw MakeTypeError("obj_ctor_property_non_object", ["search"]);
+ }
var regexp;
if (IS_STRING(re)) {
regexp = %_GetFromCache(STRING_TO_REGEXP_CACHE_ID, re);
@@ -485,6 +514,9 @@
// ECMA-262 section 15.5.4.13
function StringSlice(start, end) {
+ if (IS_NULL_OR_UNDEFINED(this)) {
+ throw MakeTypeError("obj_ctor_property_non_object", ["slice"]);
+ }
var s = TO_STRING_INLINE(this);
var s_len = s.length;
var start_i = TO_INTEGER(start);
@@ -520,6 +552,9 @@
// ECMA-262 section 15.5.4.14
function StringSplit(separator, limit) {
+ if (IS_NULL_OR_UNDEFINED(this)) {
+ throw MakeTypeError("obj_ctor_property_non_object", ["split"]);
+ }
var subject = TO_STRING_INLINE(this);
limit = (IS_UNDEFINED(limit)) ? 0xffffffff : TO_UINT32(limit);
if (limit === 0) return [];
@@ -613,6 +648,9 @@
// ECMA-262 section 15.5.4.15
function StringSubstring(start, end) {
+ if (IS_NULL_OR_UNDEFINED(this)) {
+ throw MakeTypeError("obj_ctor_property_non_object", ["subString"]);
+ }
var s = TO_STRING_INLINE(this);
var s_len = s.length;
@@ -646,6 +684,9 @@
// This is not a part of ECMA-262.
function StringSubstr(start, n) {
+ if (IS_NULL_OR_UNDEFINED(this)) {
+ throw MakeTypeError("obj_ctor_property_non_object", ["substr"]);
+ }
var s = TO_STRING_INLINE(this);
var len;
@@ -686,37 +727,59 @@
// ECMA-262, 15.5.4.16
function StringToLowerCase() {
+ if (IS_NULL_OR_UNDEFINED(this)) {
+ throw MakeTypeError("obj_ctor_property_non_object", ["toLowerCase"]);
+ }
return %StringToLowerCase(TO_STRING_INLINE(this));
}
// ECMA-262, 15.5.4.17
function StringToLocaleLowerCase() {
+ if (IS_NULL_OR_UNDEFINED(this)) {
+ throw MakeTypeError("obj_ctor_property_non_object", ["toLocaleLowerCase"]);
+ }
return %StringToLowerCase(TO_STRING_INLINE(this));
}
// ECMA-262, 15.5.4.18
function StringToUpperCase() {
+ if (IS_NULL_OR_UNDEFINED(this)) {
+ throw MakeTypeError("obj_ctor_property_non_object", ["toUpperCase"]);
+ }
return %StringToUpperCase(TO_STRING_INLINE(this));
}
// ECMA-262, 15.5.4.19
function StringToLocaleUpperCase() {
+ if (IS_NULL_OR_UNDEFINED(this)) {
+ throw MakeTypeError("obj_ctor_property_non_object", ["toLocaleUpperCase"]);
+ }
return %StringToUpperCase(TO_STRING_INLINE(this));
}
// ES5, 15.5.4.20
function StringTrim() {
+ if (IS_NULL_OR_UNDEFINED(this)) {
+ throw MakeTypeError("obj_ctor_property_non_object", ["trim"]);
+ }
return %StringTrim(TO_STRING_INLINE(this), true, true);
}
function StringTrimLeft() {
+ if (IS_NULL_OR_UNDEFINED(this)) {
+ throw MakeTypeError("obj_ctor_property_non_object", ["trimLeft"]);
+ }
return %StringTrim(TO_STRING_INLINE(this), true, false);
}
function StringTrimRight() {
+ if (IS_NULL_OR_UNDEFINED(this)) {
+ throw MakeTypeError("obj_ctor_property_non_object", ["trimRight"]);
+ }
+
return %StringTrim(TO_STRING_INLINE(this), false, true);
}
« src/ia32/builtins-ia32.cc ('K') | « src/messages.js ('k') | src/v8natives.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698