<commit_before>import { error } from '@hybrids/debug';

const map = new WeakMap();
const set = new WeakSet();

let context = null;

export function injectable(fn) {
  function wrapper(...args) {
    if (!context) {
      error('illegal invocation: %s', fn.name);
    }
    return fn.apply(context, args);
  }

  Object.defineProperty(wrapper, 'source', { value: fn });

  return wrapper;
}

export function callWithContext(currentContext, fn) {
  context = currentContext;
  const result = fn();
  context = null;

  return result;
}

export function resolve(fn, currentContext = context) {
  if (!currentContext) {
    error('illegal invocation: %s', fn.name);
  }

  return () => callWithContext(currentContext, fn);
}

export function proxy(element, constructor) {
  const controller = callWithContext(element, () => constructor());

  if (typeof Proxy === 'function') {
    return new Proxy(controller, {
      get(target, property, receiver) {
        const value = Reflect.get(target, property, receiver);

        if (typeof value === 'function') {
          return (...args) => callWithContext(element, value.bind(receiver, ...args));<commit_msg>FIX global property for context<commit_after>import { error } from '@hybrids/debug';

const CONTEXT_NAME = '__hybrids_context__';

if (!{}.hasOwnProperty.call(window, CONTEXT_NAME)) {
  Object.defineProperty(window, CONTEXT_NAME, { writable: true });
}

export function injectable(fn) {
  function wrapper(...args) {
    if (!window[CONTEXT_NAME]) {
      error('illegal invocation: %s', fn.name);
    }
    return fn.apply(window[CONTEXT_NAME], args);
  }

  Object.defineProperty(wrapper, 'source', { value: fn });

  return wrapper;
}

export function callWithContext(currentContext, fn) {
  window[CONTEXT_NAME] = currentContext;
  const result = fn();
  window[CONTEXT_NAME] = null;

  return result;
}

export function resolve(fn, currentContext = window[CONTEXT_NAME]) {
  if (!currentContext) {
    error('illegal invocation: %s', fn.name);
  }

  return () => callWithContext(currentContext, fn);
}

const map = new WeakMap();
const set = new WeakSet();

export function proxy(element, constructor) {
  const controller = callWithContext(element, () => constructor());

  if (typeof Proxy === 'function') {
    return new Proxy(controller, {
      get(target, property, receiver) {
        const value = Reflect.get(target, property, receiver);

        if (typeof value === 'function') {
          return (...args) => callWithContext(element, value.bind(receiver, ...args));
{'fraction_non_alphanumeric': 0.1453900709219858, 'fraction_numerical': 0.0, 'mean_word_length': 4.017786561264822, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2457612', 'n_tokens_mistral': 764, 'n_tokens_neox': 746, 'n_words': 198}