on master help sign in
Merge pull request #64 from fitzgen/className
1aa4600Nick Fitzgerald
js/change-list-interpreter.js+8
@@ -251,6 +251,14 @@ const OP_TABLE = [
251 const child = parent.childNodes[n];
251 const child = parent.childNodes[n];
252 child.remove();
252 child.remove();
253 return i;
253 return i;
254+ },
255+
256+ // 23
257+ function setClass(interpreter, mem8, mem32, i) {
258+ const classId = mem32[i++];
259+ const className = interpreter.getCachedString(classId);
260+ top(interpreter.stack).className = className;
261+ return i;
254 }
262 }
255];
263];
256
264
src/change_list/emitter.rs+9
@@ -263,4 +263,13 @@ define_change_list_instructions! {
263 /// child.remove()
263 /// child.remove()
264 /// ```
264 /// ```
265 remove_child(n) = 22,
265 remove_child(n) = 22,
266+
267+ /// Stack: `[... Node] -> [... Node]`
268+ ///
269+ /// ```text
270+ /// class = getCachedString(class)
271+ /// node = stack.top()
272+ /// node.className = class
273+ /// ```
274+ set_class(class) = 23,
266}
275}
src/change_list/mod.rs+12−6
@@ -229,12 +229,18 @@ impl ChangeListBuilder<'_> {
229
229
230 pub fn set_attribute(&mut self, name: &str, value: &str) {
230 pub fn set_attribute(&mut self, name: &str, value: &str) {
231 debug_assert!(self.traversal_is_committed());
231 debug_assert!(self.traversal_is_committed());
232+ if name == "class" {
233+ let class_id = self.ensure_string(value);
232− debug!("emit: set_attribute({:?}, {:?})", name, value);
234+ debug!("emit: set_class({:?})", value);
235+ self.state.emitter.set_class(class_id.into());
236+ } else {
233− let name_id = self.ensure_string(name);
237+ let name_id = self.ensure_string(name);
234− let value_id = self.ensure_string(value);
238+ let value_id = self.ensure_string(value);
239+ debug!("emit: set_attribute({:?}, {:?})", name, value);
235− self.state
240+ self.state
236− .emitter
241+ .emitter
237− .set_attribute(name_id.into(), value_id.into());
242+ .set_attribute(name_id.into(), value_id.into());
243+ }
238 }
244 }
239
245
240 pub fn remove_attribute(&mut self, name: &str) {
246 pub fn remove_attribute(&mut self, name: &str) {