1
0
mirror of https://github.com/robertkrimen/otto synced 2025-10-12 20:27:30 +08:00

Add String.toLocaleLowerCase

This commit is contained in:
Robert Krimen 2013-07-14 14:35:50 -07:00
parent e7370c43cc
commit 3d883a981e
4 changed files with 34 additions and 1 deletions

View File

@ -486,9 +486,13 @@ func builtinString_localeCompare(call FunctionCall) Value {
}
/*
An alternate version
An alternate version of String.trim
func builtinString_trim(call FunctionCall) Value {
checkObjectCoercible(call.This)
return toValue_string(strings.TrimFunc(toString(call.This), isWhiteSpaceOrLineTerminator))
}
*/
func builtinString_toLocaleLowerCase(call FunctionCall) Value {
return builtinString_toLowerCase(call)
}

1
inline
View File

@ -289,6 +289,7 @@ sub newContext {
"trimLeft", 0,
"trimRight", 0,
"localeCompare", 1,
"toLocaleLowerCase", 0,
);
return
".${class}Prototype =",

View File

@ -1731,6 +1731,25 @@ func _newContext(runtime *_runtime) {
call: _nativeCallFunction(builtinString_localeCompare),
},
}
toLocaleLowerCase_function := &_object{
runtime: runtime,
class: "Function",
objectClass: _classObject,
prototype: runtime.Global.FunctionPrototype,
extensible: true,
property: map[string]_property{
"length": _property{
mode: 0,
value: Value{
_valueType: valueNumber,
value: 0,
},
},
},
value: _functionObject{
call: _nativeCallFunction(builtinString_toLocaleLowerCase),
},
}
fromCharCode_function := &_object{
runtime: runtime,
class: "Function",
@ -1905,6 +1924,13 @@ func _newContext(runtime *_runtime) {
value: localeCompare_function,
},
},
"toLocaleLowerCase": _property{
mode: 0101,
value: Value{
_valueType: valueObject,
value: toLocaleLowerCase_function,
},
},
},
}
runtime.Global.String = &_object{

View File

@ -218,6 +218,8 @@ func TestString_toCase(t *testing.T) {
test := runTest()
test(`"abc".toLowerCase()`, "abc")
test(`"ABC".toLowerCase()`, "abc")
test(`"abc".toLocaleLowerCase()`, "abc")
test(`"ABC".toLocaleLowerCase()`, "abc")
test(`"abc".toUpperCase()`, "ABC")
test(`"ABC".toUpperCase()`, "ABC")
}