Lines Matching refs:cref
276 function handle_autoload(cref, name) {
277 if (!cref.$$autoload[name].loaded) {
278 cref.$$autoload[name].loaded = true;
280 Opal.Kernel.$require(cref.$$autoload[name].path);
282 cref.$$autoload[name].exception = e;
285 cref.$$autoload[name].required = true;
286 if (cref.$$const[name] != null) {
287 cref.$$autoload[name].success = true;
288 return cref.$$const[name];
290 } else if (cref.$$autoload[name].loaded && !cref.$$autoload[name].required) {
291 if (cref.$$autoload[name].exception) { throw cref.$$autoload[name].exception; }
303 // - constant reference (cref): the module/class that acts as a namespace
307 // Get the constant in the scope of the current cref
308 function const_get_name(cref, name) {
309 if (cref) {
310 if (cref.$$const[name] != null) { return cref.$$const[name]; }
311 if (cref.$$autoload && cref.$$autoload[name]) {
312 return handle_autoload(cref, name);
336 function const_lookup_ancestors(cref, name) {
339 if (cref == null) return;
341 ancestors = $ancestors(cref);
353 // but only if cref is missing or a module.
354 function const_lookup_Object(cref, name) {
355 if (cref == null || cref.$$is_module) {
361 function const_missing(cref, name) {
362 return (cref || _Object).$const_missing(name);
365 // Look for the constant just in the current cref or call `#const_missing`
366 Opal.const_get_local = function(cref, name, skip_missing) {
369 if (cref == null) return;
371 if (cref === '::') cref = _Object;
373 if (!cref.$$is_module && !cref.$$is_class) {
374 $raise(Opal.TypeError, cref.toString() + " is not a class/module");
377 result = const_get_name(cref, name);
378 return result != null || skip_missing ? result : const_missing(cref, name);
381 // Look for the constant relative to a cref or call `#const_missing` (when the
383 Opal.const_get_qualified = function(cref, name, skip_missing) {
388 result = const_get_name(_Object, cref);
391 return Opal.const_get_qualified(_Object, cref, skip_missing);
394 if (cref == null) return;
396 if (cref === '::') cref = _Object;
398 if (!cref.$$is_module && !cref.$$is_class) {
399 $raise(Opal.TypeError, cref.toString() + " is not a class/module");
402 if ((cache = cref.$$const_cache) == null) {
403 $prop(cref, '$$const_cache', Object.create(null));
404 cache = cref.$$const_cache;
409 ((result = const_get_name(cref, name)) != null) ||
410 ((result = const_lookup_ancestors(cref, name)) != null);
416 return result != null || skip_missing ? result : const_missing(cref, name);
423 // cref ancestors or call `#const_missing` (when the constant has no :: prefix).
425 var cref = nesting[0], result, current_version = Opal.const_cache_version, cache, cached;
434 ((result = const_get_name(cref, name)) != null) ||
436 ((result = const_lookup_ancestors(cref, name)) != null) ||
437 ((result = const_lookup_Object(cref, name)) != null);
444 return result != null || skip_missing ? result : const_missing(cref, name);
447 // Register the constant on a cref and opportunistically set the name of
449 function $const_set(cref, name, value) {
452 if (cref == null || cref === '::') cref = _Object;
456 if (value.$$base_module == null) value.$$base_module = cref;
459 cref.$$const = (cref.$$const || Object.create(null));
461 if (name in cref.$$const || ("$$autoload" in cref && name in cref.$$autoload)) {
465 cref.$$const[name] = value;
470 cref.$$ = cref.$$const;
475 if (cref === _Object) Opal[name] = value;
478 $prop(cref, name, value);
480 if (new_const && cref.$const_added && !cref.$const_added.$$pristine) {
481 cref.$const_added(name);
488 // Get all the constants reachable from a given cref, by default will include
490 Opal.constants = function(cref, inherit) {
493 var module, modules = [cref], i, ii, constants = {}, constant;
495 if (inherit) modules = modules.concat($ancestors(cref));
496 …if (inherit && cref.$$is_module) modules = modules.concat([Opal.Object]).concat($ancestors(Opal.Ob…
502 if (cref !== _Object && module == _Object) break;
517 // Remove a constant from a cref.
518 Opal.const_remove = function(cref, name) {
521 if (cref.$$const[name] != null) {
522 var old = cref.$$const[name];
523 delete cref.$$const[name];
527 if (cref.$$autoload && cref.$$autoload[name]) {
528 delete cref.$$autoload[name];
532 $raise(Opal.NameError, "constant "+cref+"::"+cref.$name()+" not defined");