mirror of
https://github.com/servo/servo.git
synced 2025-06-13 19:04:30 +00:00
Use byte string instead of handcrafted byte array
This commit is contained in:
parent
4a95bce9f2
commit
ab4059ca21
2 changed files with 16 additions and 40 deletions
|
@ -1287,16 +1287,11 @@ class MethodDefiner(PropertyDefiner):
|
||||||
accessor = m.get("nativeName", m["name"])
|
accessor = m.get("nativeName", m["name"])
|
||||||
if accessor[0:3] != 'JS_':
|
if accessor[0:3] != 'JS_':
|
||||||
accessor = "%s as NonNullJSNative" % accessor
|
accessor = "%s as NonNullJSNative" % accessor
|
||||||
return (m["name"], accessor, jitinfo, m["length"], m["flags"])
|
return (str_to_const_array(m["name"]), accessor, jitinfo, m["length"], m["flags"])
|
||||||
|
|
||||||
def stringDecl(m):
|
return self.generatePrefableArray(
|
||||||
return "const %s_name: [u8; %i] = %s;\n" % (m["name"], len(m["name"]) + 1,
|
|
||||||
str_to_const_array(m["name"]))
|
|
||||||
|
|
||||||
decls = ''.join([stringDecl(m) for m in array])
|
|
||||||
return decls + self.generatePrefableArray(
|
|
||||||
array, name,
|
array, name,
|
||||||
' JSFunctionSpec { name: &%s_name as *const u8 as *const libc::c_char, call: JSNativeWrapper {op: Some(%s), info: %s}, nargs: %s, flags: %s as u16, selfHostedName: 0 as *const libc::c_char }',
|
' JSFunctionSpec { name: %s as *const u8 as *const libc::c_char, call: JSNativeWrapper {op: Some(%s), info: %s}, nargs: %s, flags: %s as u16, selfHostedName: 0 as *const libc::c_char }',
|
||||||
' JSFunctionSpec { name: 0 as *const libc::c_char, call: JSNativeWrapper {op: None, info: 0 as *const JSJitInfo}, nargs: 0, flags: 0, selfHostedName: 0 as *const libc::c_char }',
|
' JSFunctionSpec { name: 0 as *const libc::c_char, call: JSNativeWrapper {op: None, info: 0 as *const JSJitInfo}, nargs: 0, flags: 0, selfHostedName: 0 as *const libc::c_char }',
|
||||||
'JSFunctionSpec',
|
'JSFunctionSpec',
|
||||||
specData)
|
specData)
|
||||||
|
@ -1353,19 +1348,12 @@ class AttrDefiner(PropertyDefiner):
|
||||||
"native" : accessor})
|
"native" : accessor})
|
||||||
|
|
||||||
def specData(attr):
|
def specData(attr):
|
||||||
return (attr.identifier.name, flags(attr), getter(attr),
|
return (str_to_const_array(attr.identifier.name), flags(attr), getter(attr),
|
||||||
setter(attr))
|
setter(attr))
|
||||||
|
|
||||||
def stringDecl(attr):
|
return self.generatePrefableArray(
|
||||||
name = attr.identifier.name
|
|
||||||
return "const %s_name: [u8; %i] = %s;\n" % (name, len(name) + 1,
|
|
||||||
str_to_const_array(name))
|
|
||||||
|
|
||||||
decls = ''.join([stringDecl(m) for m in array])
|
|
||||||
|
|
||||||
return decls + self.generatePrefableArray(
|
|
||||||
array, name,
|
array, name,
|
||||||
' JSPropertySpec { name: &%s_name as *const u8 as *const libc::c_char, tinyid: 0, flags: ((%s) & 0xFF) as u8, getter: %s, setter: %s }',
|
' JSPropertySpec { name: %s as *const u8 as *const libc::c_char, tinyid: 0, flags: ((%s) & 0xFF) as u8, getter: %s, setter: %s }',
|
||||||
' JSPropertySpec { name: 0 as *const libc::c_char, tinyid: 0, flags: 0, getter: JSPropertyOpWrapper {op: None, info: 0 as *const JSJitInfo}, setter: JSStrictPropertyOpWrapper {op: None, info: 0 as *const JSJitInfo} }',
|
' JSPropertySpec { name: 0 as *const libc::c_char, tinyid: 0, flags: 0, getter: JSPropertyOpWrapper {op: None, info: 0 as *const JSJitInfo}, setter: JSStrictPropertyOpWrapper {op: None, info: 0 as *const JSJitInfo} }',
|
||||||
'JSPropertySpec',
|
'JSPropertySpec',
|
||||||
specData)
|
specData)
|
||||||
|
@ -1384,18 +1372,12 @@ class ConstDefiner(PropertyDefiner):
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
def specData(const):
|
def specData(const):
|
||||||
return (const.identifier.name,
|
return (str_to_const_array(const.identifier.name),
|
||||||
convertConstIDLValueToJSVal(const.value))
|
convertConstIDLValueToJSVal(const.value))
|
||||||
|
|
||||||
def stringDecl(const):
|
return self.generatePrefableArray(
|
||||||
name = const.identifier.name
|
|
||||||
return "const %s_name: &'static [u8] = &%s;\n" % (name, str_to_const_array(name))
|
|
||||||
|
|
||||||
decls = ''.join([stringDecl(m) for m in array])
|
|
||||||
|
|
||||||
return decls + self.generatePrefableArray(
|
|
||||||
array, name,
|
array, name,
|
||||||
' ConstantSpec { name: %s_name, value: %s }',
|
' ConstantSpec { name: %s, value: %s }',
|
||||||
None,
|
None,
|
||||||
'ConstantSpec',
|
'ConstantSpec',
|
||||||
specData)
|
specData)
|
||||||
|
@ -1583,10 +1565,9 @@ class CGDOMJSClass(CGThing):
|
||||||
flags = "0"
|
flags = "0"
|
||||||
slots = "1"
|
slots = "1"
|
||||||
return """\
|
return """\
|
||||||
const Class_name: [u8; %i] = %s;
|
|
||||||
static Class: DOMJSClass = DOMJSClass {
|
static Class: DOMJSClass = DOMJSClass {
|
||||||
base: js::Class {
|
base: js::Class {
|
||||||
name: &Class_name as *const u8 as *const libc::c_char,
|
name: %s as *const u8 as *const libc::c_char,
|
||||||
flags: JSCLASS_IS_DOMJSCLASS | %s | (((%s) & JSCLASS_RESERVED_SLOTS_MASK) << JSCLASS_RESERVED_SLOTS_SHIFT), //JSCLASS_HAS_RESERVED_SLOTS(%s),
|
flags: JSCLASS_IS_DOMJSCLASS | %s | (((%s) & JSCLASS_RESERVED_SLOTS_MASK) << JSCLASS_RESERVED_SLOTS_SHIFT), //JSCLASS_HAS_RESERVED_SLOTS(%s),
|
||||||
addProperty: Some(JS_PropertyStub),
|
addProperty: Some(JS_PropertyStub),
|
||||||
delProperty: Some(JS_PropertyStub),
|
delProperty: Some(JS_PropertyStub),
|
||||||
|
@ -1649,8 +1630,7 @@ static Class: DOMJSClass = DOMJSClass {
|
||||||
},
|
},
|
||||||
dom_class: %s
|
dom_class: %s
|
||||||
};
|
};
|
||||||
""" % (len(self.descriptor.interface.identifier.name) + 1,
|
""" % (str_to_const_array(self.descriptor.interface.identifier.name),
|
||||||
str_to_const_array(self.descriptor.interface.identifier.name),
|
|
||||||
flags, slots, slots,
|
flags, slots, slots,
|
||||||
FINALIZE_HOOK_NAME, traceHook,
|
FINALIZE_HOOK_NAME, traceHook,
|
||||||
self.descriptor.outerObjectHook,
|
self.descriptor.outerObjectHook,
|
||||||
|
@ -1658,7 +1638,7 @@ static Class: DOMJSClass = DOMJSClass {
|
||||||
CGIndenter(CGGeneric(DOMClass(self.descriptor))).define())
|
CGIndenter(CGGeneric(DOMClass(self.descriptor))).define())
|
||||||
|
|
||||||
def str_to_const_array(s):
|
def str_to_const_array(s):
|
||||||
return "[" + (", ".join(map(lambda x: "'" + x + "' as u8", list(s)) + ['0 as u8'])) + "]"
|
return "b\"%s\\0\"" % s
|
||||||
|
|
||||||
class CGPrototypeJSClass(CGThing):
|
class CGPrototypeJSClass(CGThing):
|
||||||
def __init__(self, descriptor):
|
def __init__(self, descriptor):
|
||||||
|
@ -1667,9 +1647,8 @@ class CGPrototypeJSClass(CGThing):
|
||||||
|
|
||||||
def define(self):
|
def define(self):
|
||||||
return """\
|
return """\
|
||||||
const PrototypeClassName__: [u8; %s] = %s;
|
|
||||||
static PrototypeClass: JSClass = JSClass {
|
static PrototypeClass: JSClass = JSClass {
|
||||||
name: &PrototypeClassName__ as *const u8 as *const libc::c_char,
|
name: %s as *const u8 as *const libc::c_char,
|
||||||
flags: (1 & JSCLASS_RESERVED_SLOTS_MASK) << JSCLASS_RESERVED_SLOTS_SHIFT, //JSCLASS_HAS_RESERVED_SLOTS(1)
|
flags: (1 & JSCLASS_RESERVED_SLOTS_MASK) << JSCLASS_RESERVED_SLOTS_SHIFT, //JSCLASS_HAS_RESERVED_SLOTS(1)
|
||||||
addProperty: Some(JS_PropertyStub),
|
addProperty: Some(JS_PropertyStub),
|
||||||
delProperty: Some(JS_PropertyStub),
|
delProperty: Some(JS_PropertyStub),
|
||||||
|
@ -1686,8 +1665,7 @@ static PrototypeClass: JSClass = JSClass {
|
||||||
trace: None,
|
trace: None,
|
||||||
reserved: [0 as *mut libc::c_void; 40]
|
reserved: [0 as *mut libc::c_void; 40]
|
||||||
};
|
};
|
||||||
""" % (len(self.descriptor.interface.identifier.name + "Prototype") + 1,
|
""" % str_to_const_array(self.descriptor.interface.identifier.name + "Prototype")
|
||||||
str_to_const_array(self.descriptor.interface.identifier.name + "Prototype"))
|
|
||||||
|
|
||||||
class CGInterfaceObjectJSClass(CGThing):
|
class CGInterfaceObjectJSClass(CGThing):
|
||||||
def __init__(self, descriptor):
|
def __init__(self, descriptor):
|
||||||
|
|
|
@ -203,9 +203,7 @@ impl<'a> EventTargetHelpers for JSRef<'a, EventTarget> {
|
||||||
let lineno = 0; //XXXjdm need to get a real number here
|
let lineno = 0; //XXXjdm need to get a real number here
|
||||||
|
|
||||||
let nargs = 1; //XXXjdm not true for onerror
|
let nargs = 1; //XXXjdm not true for onerror
|
||||||
const ARG_NAME: [c_char; 6] =
|
static mut ARG_NAMES: [*const c_char; 1] = [b"event\0" as *const u8 as *const c_char];
|
||||||
['e' as c_char, 'v' as c_char, 'e' as c_char, 'n' as c_char, 't' as c_char, 0];
|
|
||||||
static mut ARG_NAMES: [*const c_char; 1] = [&ARG_NAME as *const c_char];
|
|
||||||
|
|
||||||
let source: Vec<u16> = source.utf16_units().collect();
|
let source: Vec<u16> = source.utf16_units().collect();
|
||||||
let handler = unsafe {
|
let handler = unsafe {
|
||||||
|
@ -213,7 +211,7 @@ impl<'a> EventTargetHelpers for JSRef<'a, EventTarget> {
|
||||||
ptr::null_mut(),
|
ptr::null_mut(),
|
||||||
name.as_ptr(),
|
name.as_ptr(),
|
||||||
nargs,
|
nargs,
|
||||||
&ARG_NAMES as *const *const c_char as *mut *const c_char,
|
ARG_NAMES.as_mut_ptr(),
|
||||||
source.as_ptr(),
|
source.as_ptr(),
|
||||||
source.len() as size_t,
|
source.len() as size_t,
|
||||||
url.as_ptr(),
|
url.as_ptr(),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue