Skip to main content

define_class

Function define_class 

Source
pub fn define_class(
    name: &str,
    descriptor_json: &[u8],
    env: &ClassEnv,
) -> Result<ClassDescriptor>
Expand description

Defines a class (16.2): checks descriptor_json, the descriptor as the author wrote it, flattens it onto its parent and checks the result. Returns the flattened descriptor; its hash is the class hash. Checks in this order and reports the first failure:

  1. name is a full name (2.3, E_CANON_NAME) under env.definer(), its namespace being the definer’s or below it (E_CLASS_OWNER);
  2. the descriptor as written (ClassDescriptor::from_json);
  3. the parent, when there is one: known to env (E_CLASS_PARENT), no parent key declared again (E_CLASS_INHERIT); then flattening (keys: the parent’s then the class’s own; order: the parent’s then the class’s own; methods: the parent’s overlaid by the class’s own; implements: the union; every other member the class’s own; parent stays);
  4. overrides (E_CLASS_FINAL, then E_CLASS_OVERRIDE);
  5. the flattened descriptor, by 16.1;
  6. the methods in JCS order of names (E_CLASS_METHOD; the lookup method’s own rule is E_CLASS_MEMBER);
  7. extent functions (E_CLASS_MEMBER);
  8. implements (E_CLASS_INTERFACE).