Replace all references of an object by their actual object value.
324200
def resolve_all_references(obj, browsed: [], cache: {})
            return obj if browsed.include?(obj)
            browsed.push(obj)

            if obj.is_a?(ObjectStream)
                obj.each do |subobj|
                    resolve_all_references(subobj, browsed: browsed, cache: cache)
                end
            end

            if obj.is_a?(Stream)
                resolve_all_references(obj.dictionary, browsed: browsed, cache: cache)
            end

            if obj.is_a?(CompoundObject)
                obj.update_values! do |subobj|
                    if subobj.is_a?(Reference)
                        subobj = (cache[subobj] ||= subobj.solve.copy)
                        subobj.no = subobj.generation = 0
                        subobj.parent = obj
                    end

                    resolve_all_references(subobj, browsed: browsed, cache: cache)
                end
            end

            obj
        end
1125654
def evaluate_object(obj, cls=None, cache=False, **kwargs):
        """"""
        old_obj = obj
        if isinstance(obj, Element):
            if cache:
                obj = obj.evaluate_cached(**kwargs)
            else:
                obj = obj.evaluate(cache=cache, **kwargs)

        if cls is not None and type(obj) != cls:
            obj = cls(obj)

        for attr in ('string', 'location', 'tokens'):
            if hasattr(old_obj, attr):
                setattr(obj, attr, getattr(old_obj, attr))

        return obj
610190
def patch_object(obj, attr, value):
    
    orig = getattr(obj, attr, no_value)

    try:
        setattr(obj, attr, value)

        yield obj
    finally:
        try:
            if orig is no_value:
                delattr(obj, attr)
            else:
                setattr(obj, attr, orig)
        except:
            pass
89905
function setProto (oldObj, newObj) {
  Object.keys(newObj).forEach(key => {
    if (!oldObj[key]) {
      oldObj[key] = JSON.parse(JSON.stringify(newObj[key]))
    }
  })
}
5375
public void replaceValue(Object bodyObj, Object replaceValue) {
        Object parentObj = bodyObj;

        if(this.listChild) {
            ValidationData rootListParent = this.findListParent();
            if(this.deepLevel - rootListParent.deepLevel > 1 ){
                parentObj = this.parent.getValue(bodyObj);
            }
        }
        else {
            if (this.parentId != null) {
                parentObj = this.parent.getValue(bodyObj);
            }
        }

        this.setter(this, parentObj, replaceValue);
    }
795943
def to_native(self, obj, name, value):  # pylint:disable=unused-argument
		""""""
		
		if self.mapping:
			for original, new in self.mapping.items():
				value = value.replace(original, new)
		
		return load(value, self.namespace)
172492
function ref_copy_self(self, obj) {
	//console.log( 'at ref_copy_self(): self = ' + JSON.stringify(self) + ', obj = ' + JSON.stringify(obj) );
	ARRAY(Object.keys(obj)).forEach(function(key) {
		self[key] = ref_copy(obj[key]);
	});
}
261409
def replace(self, new):
        """"""
        assert self.parent is not None, str(self)
        assert new is not None
        if not isinstance(new, list):
            new = [new]
        l_children = []
        found = False
        for ch in self.parent.children:
            if ch is self:
                assert not found, (self.parent.children, self, new)
                if new is not None:
                    l_children.extend(new)
                found = True
            else:
                l_children.append(ch)
        assert found, (self.children, self, new)
        self.parent.changed()
        self.parent.children = l_children
        for x in new:
            x.parent = self.parent
        self.parent = None
1102737
def replace(parent, idx, value, check_value=_NO_VAL):
  """"""
  if isinstance(parent, dict):
    if idx not in parent:
      raise JSONPatchError("Item does not exist")
  elif isinstance(parent, list):
    idx = int(idx)
    if idx < 0 or idx >= len(parent):
      raise JSONPatchError("List index out of range")
  if check_value is not _NO_VAL:
    if parent[idx] != check_value:
      raise JSONPatchError("Check value did not pass")
  parent[idx] = value
1095705
function replacePropagatingVersions(uri, data) {
  if (references.isPropagatingVersion(uri)) {
    references.replaceAllVersions(uri.split('@')[1])(data);
  }

  return data;
}
4347
function replaceObject(dryReplacer, value, chain, flags, is_wrap, holder, path, value_paths, key) {

	var class_name,
	    seen_path,
	    new_value,
	    replaced,
	    is_array,
	    keys,
	    last,
	    temp,
	    len,
	    i;

	if (typeof value.constructor == 'function') {
		class_name = value.constructor.name;
	} else {
		class_name = 'Object';
	}

	// See if the chain needs popping
	while (len = chain.length) {

		// If the current object at the end of the chain does not
		// match the current holder, move one up
		// Don't mess with the chain if this is a wrap object
		if (!is_wrap && holder !== chain[len-1]) {

			last = chain.pop();

			// Only pop the path if the popped object isn't a wrapper
			if (last && !last.__is_wrap) {
				path.pop();
			}
		} else {
			break;
		}
	}

	// Has the object been seen before?
	seen_path = value_paths.get(value);

	if (seen_path) {

		// If the path is still an array,
		// turn it into a string now
		if (typeof seen_path != 'string') {

			// First iterate over the pieces and escape them
			for (i = 0; i < seen_path.length; i++) {
				if (seen_path[i].indexOf(special_char) > -1) {
					seen_path[i] = seen_path[i].replace(special_char_rg, safe_special_char);
				}
			}

			seen_path = special_char + seen_path.join(special_char);
			value_paths.set(value, seen_path);
		}

		// Replace the value with the path
		new_value = seen_path;

		// See if the new path is shorter
		len = 1;
		for (i = 0; i < path.length; i++) {
			len += 1 + path[i].length;
		}
		len += key.length;

		if (len < seen_path.length) {
			temp = seen_path;
			seen_path = path.slice(0);

			// The key of the current value still needs to be added
			seen_path.push(key);

			// First iterate over the pieces and escape them
			for (i = 0; i < seen_path.length; i++) {
				if (seen_path[i].indexOf(special_char) > -1) {
					seen_path[i] = seen_path[i].replace(special_char_rg, safe_special_char);
				}
			}

			seen_path = special_char + seen_path.join(special_char);
			value_paths.set(value, seen_path);

			// This entry still has to refer to the longer path,
			// otherwise it'll refer to itself
			seen_path = temp;
		}

		value = new_value;

		return value;
	}

	if (!flags.is_root && !is_wrap) {
		path.push(key);
	} else {
		flags.is_root = false;
	}

	// Make a copy of the current path array
	value_paths.set(value, path.slice(0));

	if (driers[class_name] != null) {
		value = driers[class_name].fnc(holder, key, value);

		value = {
			dry: class_name,
			value: value
		};

		if (driers[class_name].options.add_path !== false) {
			value.drypath = path.slice(0);
		}

		replaced = {'': value};
	} else if (class_name === 'RegExp' && value.constructor == RegExp) {
		value = {dry: 'regexp', value: value.toString()};
		replaced = {'': value};
	} else if (class_name === 'Date' && value.constructor == Date) {
		value = {dry: 'date', value: value.toISOString()};
		replaced = {'': value};
	} else if (typeof value.toDry === 'function') {
		temp = value;
		value = value.toDry();

		// If no path was supplied in the toDry,
		// get some more class information
		if (!value.path) {
			if (temp.constructor) {
				if (!value.namespace && temp.constructor.namespace) {
					value.namespace = temp.constructor.namespace;
				}

				if (!value.dry_class) {
					value.dry_class = temp.constructor.name;
				}
			}
		}

		value.dry = 'toDry';
		value.drypath = path.slice(0);
		replaced = {'': value};
	} else if (typeof value.toJSON === 'function') {
		value = value.toJSON();
		replaced = {'': value};
	} else {
		is_array = Array.isArray(value);
	}

	if (replaced) {
		// Push the replaced object on the chain
		chain.push(replaced);

		// Jsonify the replaced object
		value = dryReplacer(replaced, false, replaced['']);

		// At least one part of the path & chain will have
		// to be popped off. This is needed for toJSON calls
		// that return primitive values
		temp = chain.pop();

		// Don't pop off anything from the path if the last item
		// from the chain was a wrapper for an object,
		// because then it'll already be popped of
		if (!(temp && temp.__is_wrap && temp.__is_object)) {
			path.pop();
		}

		// Break out of the switch
		return value;
	}

	// Push this object on the chain
	chain.push(value);

	if (is_array) {
		new_value = [];

		for (i = 0; i < value.length; i++) {
			new_value[i] = dryReplacer(value, String(i), value[i]);
		}
	} else {
		new_value = recurseGeneralObject(dryReplacer, value);
	}

	value = new_value;

	return value;
}
502397
def _reset_values(self, instance):
        """"""
        self.value = None
        self.reference.value = None
        instance.__dict__.pop(self.field_name, None)
        instance.__dict__.pop(self.reference.field_name, None)
        self.reference.delete_cached_value(instance)
562966
function shallowClone(obj) {
    let result = {};
    for (let p in obj) {
        if (obj.hasOwnProperty(p)) {
            result[p] = obj[p];
        }
    }
    return result;
}
164257
def kreplace(self, key, value):
        
        for item in self:
            if key in item:
                item[key] = value
538785
function fixrefs(scope, i) {
                        // do children first; order shouldn't matter
                        for (i = scope.children.length; --i >= 0;)
                                fixrefs(scope.children[i]);
                        for (i in scope.refs) if (HOP(scope.refs, i)) {
                                // find origin scope and propagate the reference to origin
                                for (var origin = scope.has(i), s = scope; s; s = s.parent) {
                                        s.refs[i] = origin;
                                        if (s === origin) break;
                                }
                        }
                }
261404
function resolveReferences() {

    var elementsById = context.elementsById;
    var references = context.references;

    var i, r;

    for (i = 0; (r = references[i]); i++) {
      var element = r.element;
      var reference = elementsById[r.id];
      var property = getModdleDescriptor(element).propertiesByName[r.property];

      if (!reference) {
        context.addWarning({
          message: 'unresolved reference <' + r.id + '>',
          element: r.element,
          property: r.property,
          value: r.id
        });
      }

      if (property.isMany) {
        var collection = element.get(property.name),
            idx = collection.indexOf(r);

        // we replace an existing place holder (idx != -1) or
        // append to the collection instead
        if (idx === -1) {
          idx = collection.length;
        }

        if (!reference) {
          // remove unresolvable reference
          collection.splice(idx, 1);
        } else {
          // add or update reference in collection
          collection[idx] = reference;
        }
      } else {
        element.set(property.name, reference);
      }
    }
  }
994071
function replaceKeyDeep(obj, keyMap) {
  return Object.keys(obj).reduce((memo, key)=> {

    // determine which key we are going to use
    let targetKey = keyMap[key] ? keyMap[key] : key;

    // assign the new value
    memo[targetKey] = obj[key];

    // recurse if an array
    if (Array.isArray(memo[targetKey])) {
      memo[targetKey].forEach((val, idx) => {
        if (Object.prototype.toString.call(val) === '[object Object]') {
          memo[targetKey][idx] = replaceKeyDeep(val, keyMap);
        }
      });
    } else if (Object.prototype.toString.call(memo[targetKey]) === '[object Object]') {
      // recurse if Object
      memo[targetKey] = replaceKeyDeep(memo[targetKey], keyMap);
    }

    // return the modified object
    return memo;
  }, {});
}