Example #1
0
js_val *
bootstrap_function()
{
  js_val *function = JSNFUNC(func_new, 1);
  js_val *prototype = JSFUNC(NULL);
  function->proto = prototype;
  prototype->proto = fh->object_proto;

  // Function
  // --------

  DEF(function, "prototype", prototype);

  // Function.prototype
  // ------------------

  // Properties
  DEF(prototype, "length", JSNUM(0));
  DEF(prototype, "constructor", JSNFUNC(func_new, 1));

  // Methods
  DEF(prototype, "apply", JSNFUNC(func_proto_apply, 2));
  DEF(prototype, "bind", JSNFUNC(func_proto_bind, 1));
  DEF(prototype, "call", JSNFUNC(func_proto_call, 1));
  DEF(prototype, "isGenerator", JSNFUNC(func_proto_is_generator, 0));
  DEF(prototype, "toString", JSNFUNC(func_proto_to_string, 0));

  fh->function_proto = prototype;

  return function;
}
Example #2
0
// Function.prototype.apply(thisValue[, arg1[, arg2[, ...]]])
js_val *
func_proto_bind(js_val *instance, js_args *args, eval_state *state)
{
  js_val *this = ARG(args, 0);

  // Shift off the first argument.
  args->arg = NULL;
  if (args->next)
    args = args->next;

  js_val *func = JSFUNC(instance->object.node);
  func->object.bound_this = this;
  func->object.bound_args = args;
  return func;
}
Example #3
0
	error+="out of memory";
	break;
      default:
	error+="unknown error";
      };

      EJS_THROW_ERROR(cx,obj,error.c_str());
    }
    assert(destLen>0);
    dest=(Byte *)JS_realloc(cx,dest,destLen);
    RETSTR(dest,destLen,rval);
  }

#define JSFUNC(name, args) { #name,ejszlib_##name,args,0,0}
  static JSFunctionSpec static_methods[] = {
    JSFUNC(compress,1),
    JSFUNC(uncompress,2),
    EJS_END_FUNCTIONSPEC
  };
#undef JSFUNC

  //! function called after module is loaded
  /*!
    \return JS_TRUE on success
  */
  JSBool
  ejszlib_LTX_onLoad(JSContext *cx, JSObject *module)
  {
    return JS_DefineFunctions(cx, module, static_methods);
  }