Skip to content
This repository has been archived by the owner on Aug 18, 2018. It is now read-only.

Commit

Permalink
Fix all tests on SpiderMonkey HEAD.
Browse files Browse the repository at this point in the history
- switch our global object to lazy resolution and enumeration of builtins
  • Loading branch information
jbarnette committed Apr 22, 2008
1 parent 04dd648 commit 44ce09c
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 16 deletions.
37 changes: 35 additions & 2 deletions ext/spidermonkey/context.c
Expand Up @@ -3,6 +3,38 @@
#include "error.h"
#include "idhash.h"

static JSBool global_enumerate(JSContext *js_context, JSObject *obj)
{
return JS_EnumerateStandardClasses(js_context, obj);
}

static JSBool global_resolve(
JSContext *js_context, JSObject *obj, jsval id, uintN flags, JSObject **objp)
{
if ((flags & JSRESOLVE_ASSIGNING) == 0) {
JSBool resolved_p;

assert(JS_ResolveStandardClass(js_context, obj, id, &resolved_p));
if (resolved_p) *objp = obj;
}

return JS_TRUE;
}


static JSClass OurGlobalClass = {
"global", JSCLASS_NEW_RESOLVE | JSCLASS_GLOBAL_FLAGS,
JS_PropertyStub, // addProperty
JS_PropertyStub, // delProperty
JS_PropertyStub, // getProperty
JS_PropertyStub, // setProperty
global_enumerate,
(JSResolveOp) global_resolve,
JS_ConvertStub,
JS_FinalizeStub,
JSCLASS_NO_OPTIONAL_MEMBERS
};

static VALUE global(VALUE self)
{
OurContext* context;
Expand All @@ -24,8 +56,9 @@ static VALUE evaluate(VALUE self, VALUE script)
char* scriptz = StringValuePtr(script);
jsval js;

// FIXME: should be able to pass in the 'file' name
JSBool ok = JS_EvaluateScript(context->js, context->global,
scriptz, strlen(scriptz), NULL, 1, &js);
scriptz, strlen(scriptz), "(johnson)", 1, &js);

if (!ok)
{
Expand Down Expand Up @@ -101,7 +134,7 @@ static VALUE initialize_native(VALUE self, VALUE options)
assert(context->gcthings = JS_NewObject(context->js, NULL, 0, 0));
assert(context->global = JS_NewObject(context->js, &OurGlobalClass, NULL, NULL));

assert(JS_InitStandardClasses(context->js, context->global));
// assert(JS_InitStandardClasses(context->js, context->global));
assert(JS_AddRoot(context->js, &(context->gcthings)));

JS_SetErrorReporter(context->js, error);
Expand Down
12 changes: 0 additions & 12 deletions ext/spidermonkey/context.h
Expand Up @@ -19,18 +19,6 @@ typedef struct {

} OurContext;

static JSClass OurGlobalClass = {
"global", JSCLASS_NEW_RESOLVE | JSCLASS_GLOBAL_FLAGS,
JS_PropertyStub, // addProperty
JS_PropertyStub, // delProperty
JS_PropertyStub, // getProperty
JS_PropertyStub, // setProperty
JS_EnumerateStub,
JS_ResolveStub,
JS_ConvertStub,
JS_FinalizeStub
};

void init_Johnson_SpiderMonkey_Context(VALUE spidermonkey);
VALUE Johnson_SpiderMonkey_JSLandProxy();
static JSBool define_property(JSContext *context, JSObject *obj, uintN argc, jsval *argv, jsval *retval);
Expand Down
4 changes: 2 additions & 2 deletions test/johnson/spidermonkey/js_land_proxy_test.rb
Expand Up @@ -154,9 +154,9 @@ def test_setter_calls_indexer
assert_equal(42, indexable["monkey"])
end

def test_calls_0_arity_method
def test_calls_attr_reader
@context["foo"] = Foo.new
assert_js_equal(10, "foo.bar()")
assert_js_equal(10, "foo.bar")
end

def test_calls_1_arity_method
Expand Down

0 comments on commit 44ce09c

Please sign in to comment.