mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
Introduce jsid_to_str to simplify jsval_to_str callers that have an id.
This commit is contained in:
parent
bdc7e984eb
commit
610d1649cd
2 changed files with 25 additions and 49 deletions
|
@ -4231,16 +4231,7 @@ class CGDOMJSProxyHandler_getOwnPropertyDescriptor(CGAbstractExternMethod):
|
||||||
# properties that shadow prototype properties.
|
# properties that shadow prototype properties.
|
||||||
namedGet = ("\n" +
|
namedGet = ("\n" +
|
||||||
"if set == 0 && RUST_JSID_IS_STRING(id) != 0 && !HasPropertyOnPrototype(cx, proxy, id) {\n" +
|
"if set == 0 && RUST_JSID_IS_STRING(id) != 0 && !HasPropertyOnPrototype(cx, proxy, id) {\n" +
|
||||||
" let nameVal = RUST_STRING_TO_JSVAL(RUST_JSID_TO_STRING(id));\n" +
|
" let name = Some(jsid_to_str(cx, id));\n" +
|
||||||
" //FakeDependentString name;\n"
|
|
||||||
" //if (!ConvertJSValueToString(cx, nameVal, &nameVal,\n" +
|
|
||||||
" // eStringify, eStringify, name)) {\n" +
|
|
||||||
" let strval = jsval_to_str(cx, nameVal);\n" +
|
|
||||||
" if strval.is_err() {\n" +
|
|
||||||
" return 0;\n" +
|
|
||||||
" }\n" +
|
|
||||||
" let name = Some(strval.unwrap());\n" +
|
|
||||||
"\n" +
|
|
||||||
" let this: *%s = UnwrapProxy(proxy);\n" +
|
" let this: *%s = UnwrapProxy(proxy);\n" +
|
||||||
CGIndenter(CGProxyNamedGetter(self.descriptor, templateValues)).define() + "\n" +
|
CGIndenter(CGProxyNamedGetter(self.descriptor, templateValues)).define() + "\n" +
|
||||||
"}\n") % (self.descriptor.concreteType)
|
"}\n") % (self.descriptor.concreteType)
|
||||||
|
@ -4298,33 +4289,14 @@ class CGDOMJSProxyHandler_defineProperty(CGAbstractExternMethod):
|
||||||
if namedSetter:
|
if namedSetter:
|
||||||
if not self.descriptor.operations['NamedCreator'] is namedSetter:
|
if not self.descriptor.operations['NamedCreator'] is namedSetter:
|
||||||
raise TypeError("Can't handle creator that's different from the setter")
|
raise TypeError("Can't handle creator that's different from the setter")
|
||||||
#XXXjdm need to properly support eStringify
|
|
||||||
set += ("if RUST_JSID_IS_STRING(id) != 0 {\n" +
|
set += ("if RUST_JSID_IS_STRING(id) != 0 {\n" +
|
||||||
" let nameVal: JSVal = RUST_STRING_TO_JSVAL(RUST_JSID_TO_STRING(id));\n" +
|
" let name = Some(jsid_to_str(cx, id));\n" +
|
||||||
" let strval = jsval_to_str(cx, nameVal);\n" +
|
|
||||||
" //FakeDependentString name;\n" +
|
|
||||||
" //if (!ConvertJSValueToString(cx, nameVal, &nameVal,\n" +
|
|
||||||
" // eStringify, eStringify, name)) {\n" +
|
|
||||||
" if strval.is_err() {\n" +
|
|
||||||
" return 0;\n" +
|
|
||||||
" }\n" +
|
|
||||||
" let name = Some(strval.unwrap());\n" +
|
|
||||||
"\n" +
|
|
||||||
" let this: *%s = UnwrapProxy(proxy);\n" +
|
" let this: *%s = UnwrapProxy(proxy);\n" +
|
||||||
CGIndenter(CGProxyNamedSetter(self.descriptor)).define() + "\n" +
|
CGIndenter(CGProxyNamedSetter(self.descriptor)).define() + "\n" +
|
||||||
"}\n") % (self.descriptor.concreteType)
|
"}\n") % (self.descriptor.concreteType)
|
||||||
elif self.descriptor.operations['NamedGetter']:
|
elif self.descriptor.operations['NamedGetter']:
|
||||||
set += ("if RUST_JSID_IS_STRING(id) {\n" +
|
set += ("if RUST_JSID_IS_STRING(id) {\n" +
|
||||||
" let nameVal: JSVal = RUST_STRING_TO_JSVAL(RUST_JSID_TO_STRING(id));\n" +
|
" let name = Some(jsid_to_str(cx, id));\n" +
|
||||||
" let strval = jsval_to_str(cx, nameVal);\n" +
|
|
||||||
" //FakeDependentString name;\n"
|
|
||||||
" //if (!ConvertJSValueToString(cx, nameVal, &nameVal,\n" +
|
|
||||||
" // eStringify, eStringify, name)) {\n" +
|
|
||||||
" let strval = jsval_to_str(cx, nameVal);\n" +
|
|
||||||
" if strval.is_err() {\n" +
|
|
||||||
" return 0;\n" +
|
|
||||||
" }\n" +
|
|
||||||
" let name = Some(strval.unwrap());\n" +
|
|
||||||
" let this: %%s = UnwrapProxy(proxy);\n" +
|
" let this: %%s = UnwrapProxy(proxy);\n" +
|
||||||
CGIndenter(CGProxyNamedGetter(self.descriptor)).define() +
|
CGIndenter(CGProxyNamedGetter(self.descriptor)).define() +
|
||||||
" if (found) {\n"
|
" if (found) {\n"
|
||||||
|
@ -4360,18 +4332,8 @@ class CGDOMJSProxyHandler_hasOwn(CGAbstractExternMethod):
|
||||||
|
|
||||||
namedGetter = self.descriptor.operations['NamedGetter']
|
namedGetter = self.descriptor.operations['NamedGetter']
|
||||||
if namedGetter:
|
if namedGetter:
|
||||||
#XXXjdm support eStringify
|
|
||||||
named = ("if RUST_JSID_IS_STRING(id) != 0 && !HasPropertyOnPrototype(cx, proxy, id) {\n" +
|
named = ("if RUST_JSID_IS_STRING(id) != 0 && !HasPropertyOnPrototype(cx, proxy, id) {\n" +
|
||||||
" let nameVal: JSVal = RUST_STRING_TO_JSVAL(RUST_JSID_TO_STRING(id));\n" +
|
" let name = Some(jsid_to_str(cx, id));\n" +
|
||||||
" let strval = jsval_to_str(cx, nameVal);\n" +
|
|
||||||
" //FakeDependentString name;\n"
|
|
||||||
" //if (!ConvertJSValueToString(cx, nameVal, &nameVal,\n" +
|
|
||||||
" // eStringify, eStringify, name)) {\n" +
|
|
||||||
" if strval.is_err() {\n" +
|
|
||||||
" return 0;\n" +
|
|
||||||
" }\n" +
|
|
||||||
" let name = Some(strval.unwrap());\n" +
|
|
||||||
"\n" +
|
|
||||||
" let this: *%s = UnwrapProxy(proxy);\n" +
|
" let this: *%s = UnwrapProxy(proxy);\n" +
|
||||||
CGIndenter(CGProxyNamedGetter(self.descriptor)).define() + "\n" +
|
CGIndenter(CGProxyNamedGetter(self.descriptor)).define() + "\n" +
|
||||||
" *bp = found as JSBool;\n"
|
" *bp = found as JSBool;\n"
|
||||||
|
@ -4439,13 +4401,7 @@ if expando.is_not_null() {
|
||||||
namedGetter = self.descriptor.operations['NamedGetter']
|
namedGetter = self.descriptor.operations['NamedGetter']
|
||||||
if namedGetter and False: #XXXjdm unfinished
|
if namedGetter and False: #XXXjdm unfinished
|
||||||
getNamed = ("if (JSID_IS_STRING(id)) {\n" +
|
getNamed = ("if (JSID_IS_STRING(id)) {\n" +
|
||||||
" JS::Value nameVal = STRING_TO_JSVAL(JSID_TO_STRING(id));\n" +
|
" let name = Some(jsid_to_str(cx, id));\n" +
|
||||||
" FakeDependentString name;\n"
|
|
||||||
" if (!ConvertJSValueToString(cx, nameVal, &nameVal,\n" +
|
|
||||||
" eStringify, eStringify, name)) {\n" +
|
|
||||||
" return false;\n" +
|
|
||||||
" }\n" +
|
|
||||||
"\n" +
|
|
||||||
" let this = UnwrapProxy(proxy);\n" +
|
" let this = UnwrapProxy(proxy);\n" +
|
||||||
CGIndenter(CGProxyNamedGetter(self.descriptor, templateValues)).define() +
|
CGIndenter(CGProxyNamedGetter(self.descriptor, templateValues)).define() +
|
||||||
"}\n") % (self.descriptor.concreteType)
|
"}\n") % (self.descriptor.concreteType)
|
||||||
|
|
|
@ -29,6 +29,7 @@ use js::jsapi::{JS_ValueToString, JS_GetReservedSlot, JS_SetReservedSlot};
|
||||||
use js::jsapi::{JSContext, JSObject, JSBool, jsid, JSClass, JSNative, JSTracer};
|
use js::jsapi::{JSContext, JSObject, JSBool, jsid, JSClass, JSNative, JSTracer};
|
||||||
use js::jsapi::{JSFunctionSpec, JSPropertySpec, JSVal, JSPropertyDescriptor};
|
use js::jsapi::{JSFunctionSpec, JSPropertySpec, JSVal, JSPropertyDescriptor};
|
||||||
use js::jsapi::{JSPropertyOp, JSStrictPropertyOp, JS_NewGlobalObject, JS_InitStandardClasses};
|
use js::jsapi::{JSPropertyOp, JSStrictPropertyOp, JS_NewGlobalObject, JS_InitStandardClasses};
|
||||||
|
use js::jsapi::{JSString};
|
||||||
use js::jsfriendapi::bindgen::JS_NewObjectWithUniqueType;
|
use js::jsfriendapi::bindgen::JS_NewObjectWithUniqueType;
|
||||||
use js::{JSPROP_ENUMERATE, JSVAL_NULL, JSCLASS_IS_GLOBAL, JSCLASS_IS_DOMJSCLASS};
|
use js::{JSPROP_ENUMERATE, JSVAL_NULL, JSCLASS_IS_GLOBAL, JSCLASS_IS_DOMJSCLASS};
|
||||||
use js::{JSPROP_PERMANENT, JSID_VOID, JSPROP_NATIVE_ACCESSORS, JSPROP_GETTER};
|
use js::{JSPROP_PERMANENT, JSID_VOID, JSPROP_NATIVE_ACCESSORS, JSPROP_GETTER};
|
||||||
|
@ -191,6 +192,25 @@ pub unsafe fn squirrel_away<T>(x: @mut T) -> *Box<T> {
|
||||||
y
|
y
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[fixed_stack_segment]
|
||||||
|
pub fn jsstring_to_str(cx: *JSContext, s: *JSString) -> ~str {
|
||||||
|
unsafe {
|
||||||
|
let length = 0;
|
||||||
|
let chars = JS_GetStringCharsAndLength(cx, s, &length);
|
||||||
|
do vec::raw::buf_as_slice(chars, length as uint) |char_vec| {
|
||||||
|
str::from_utf16(char_vec)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[fixed_stack_segment]
|
||||||
|
pub fn jsid_to_str(cx: *JSContext, id: jsid) -> ~str {
|
||||||
|
unsafe {
|
||||||
|
assert!(RUST_JSID_IS_STRING(id) != 0);
|
||||||
|
jsstring_to_str(cx, RUST_JSID_TO_STRING(id))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//XXX very incomplete
|
//XXX very incomplete
|
||||||
#[fixed_stack_segment]
|
#[fixed_stack_segment]
|
||||||
pub fn jsval_to_str(cx: *JSContext, v: JSVal) -> Result<~str, ()> {
|
pub fn jsval_to_str(cx: *JSContext, v: JSVal) -> Result<~str, ()> {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue