Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Remaining test regressions fixed or filed as issues #103

Merged
merged 6 commits into from

2 participants

@tschneidereit

With these commits, V8Monkey should be in the same state it was last Spring, test-wise.

As mentioned in #102, I disabled test_IsFunction as it doesn't seem to be valid at all, currently. Other than that, all tests pass and I think the amount of leaked roots didn't change, either.

@zpao
Owner

Just 1 nit in a couple places: watch the indent level (2 instead of 4) - we should put some modelines in there.

@zpao

Can you add a comment here mentioning how this will be used?

@zpao zpao merged commit 0280cf7 into zpao:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
3  js/src/v8api/functiontemplate.cpp
@@ -190,7 +190,8 @@ FunctionTemplate::GetFunction(JSObject* parent)
name = String::Empty();
String::AsciiValue fnName(name);
JSFunction* func =
- JS_NewFunction(cx(), CallCallback, 0, JSFUN_CONSTRUCTOR, NULL, *fnName);
+ js::NewFunctionWithReserved(cx(), CallCallback, 0, JSFUN_CONSTRUCTOR,
+ NULL, *fnName);
JSObject* obj = JS_GetFunctionObject(func);
Object o(obj);
Local<String> prototypeStr = String::NewSymbol("prototype");
View
43 js/src/v8api/object.cpp
@@ -74,11 +74,11 @@ JSBool Object::JSAPIPropertyGetter(JSContext* cx, uintN argc, jsval* vp) {
ApiExceptionBoundary boundary;
HandleScope scope;
JSObject* fnObj = JSVAL_TO_OBJECT(JS_CALLEE(cx, vp));
- jsval accessorOwner = JS_GetReservedSlot(fnObj, 0);
+ jsval accessorOwner = js::GetFunctionNativeReserved(fnObj, 0);
JS_ASSERT(JSVAL_IS_OBJECT(accessorOwner));
Object o(JSVAL_TO_OBJECT(accessorOwner));
- jsval name = JS_GetReservedSlot(fnObj, 1);
+ jsval name = js::GetFunctionNativeReserved(fnObj, 1);
jsid id;
(void) JS_ValueToId(cx, name, &id);
@@ -93,11 +93,11 @@ JSBool Object::JSAPIPropertySetter(JSContext* cx, uintN argc, jsval* vp) {
ApiExceptionBoundary boundary;
HandleScope scope;
JSObject* fnObj = JSVAL_TO_OBJECT(JS_CALLEE(cx, vp));
- jsval accessorOwner = JS_GetReservedSlot(fnObj, 0);
+ jsval accessorOwner = js::GetFunctionNativeReserved(fnObj, 0);
JS_ASSERT(JSVAL_IS_OBJECT(accessorOwner));
Object o(JSVAL_TO_OBJECT(accessorOwner));
- jsval name = JS_GetReservedSlot(fnObj, 1);
+ jsval name = js::GetFunctionNativeReserved(fnObj, 1);
jsid id;
(void) JS_ValueToId(cx, name, &id);
@@ -271,20 +271,22 @@ Object::SetAccessor(Handle<String> name,
jsid propid;
JS_ValueToId(cx(), name->native(), &propid);
- JSFunction* getterFn = JS_NewFunction(cx(), JSAPIPropertyGetter, 0, 0, NULL, NULL);
+ JSFunction* getterFn =
+ js::NewFunctionWithReserved(cx(), JSAPIPropertyGetter, 0, 0, NULL, NULL);
if (!getterFn)
return false;
JSObject *getterObj = JS_GetFunctionObject(getterFn);
- JSFunction* setterFn = JS_NewFunction(cx(), JSAPIPropertySetter, 1, 0, NULL, NULL);
+ JSFunction* setterFn =
+ js::NewFunctionWithReserved(cx(), JSAPIPropertySetter, 1, 0, NULL, NULL);
if (!setterFn)
return false;
JSObject *setterObj = JS_GetFunctionObject(setterFn);
- JS_SetReservedSlot(getterObj, 0, native());
- JS_SetReservedSlot(getterObj, 1, name->native());
- JS_SetReservedSlot(setterObj, 0, native());
- JS_SetReservedSlot(setterObj, 1, name->native());
+ js::SetFunctionNativeReserved(getterObj, 0, native());
+ js::SetFunctionNativeReserved(getterObj, 1, name->native());
+ js::SetFunctionNativeReserved(setterObj, 0, native());
+ js::SetFunctionNativeReserved(setterObj, 1, name->native());
uintN attributes = JSPROP_GETTER | JSPROP_SETTER | JSPROP_SHARED;
if (!JS_DefinePropertyById(cx(), *this, propid,
@@ -375,10 +377,18 @@ Object::InternalFieldCount()
Local<Value>
Object::GetInternalField(int index)
{
- jsval v = JS_GetReservedSlot(*this, index);
- if (JSVAL_IS_VOID(v)) {
- return Local<Value>();
+ jsval v = JSVAL_VOID;
+ if (JS_ObjectIsFunction(cx(), *this)) {
+ v = js::GetFunctionNativeReserved(*this, index);
}
+ else {
+ v = JS_GetReservedSlot(*this, index);
+ }
+ // TODO: verify that it's ok to simply remove this. It should be, as creating
+ // a Value with a void jsval seems to be fine.
+// if (JSVAL_IS_VOID(v)) {
+// return Local<Value>();
+// }
Value value(v);
return Local<Value>::New(&value);
}
@@ -387,7 +397,12 @@ void
Object::SetInternalField(int index,
Handle<Value> value)
{
- (void) JS_SetReservedSlot(*this, index, value->native());
+ if (JS_ObjectIsFunction(cx(), *this)) {
+ js::SetFunctionNativeReserved(*this, index, value->native());
+ }
+ else {
+ (void) JS_SetReservedSlot(*this, index, value->native());
+ }
}
void*
View
2  js/src/v8api/test/test_value.cpp
@@ -112,7 +112,7 @@ test_IsArray()
Test gTests[] = {
TEST(test_IntegerConversion),
TEST(test_BooleanConversion),
- TEST(test_IsFunction),
+ DISABLED_TEST(test_IsFunction, 102),
TEST(test_IsArray),
};
View
33 js/src/v8api/v8.cpp
@@ -726,17 +726,17 @@ JSScript* ScriptData::GenerateScript(void *aData, int aLen) {
//// Script class
JS_STATIC_ASSERT(sizeof(Script) == sizeof(GCReference));
-
-Handle<Object> Script::InternalObject() {
- if (JSVAL_IS_NULL(mVal))
- {
- JSObject* obj = JS_NewObject(cx(), NULL, NULL, NULL);
- mVal = OBJECT_TO_JSVAL(obj);
- }
- Object o(JSVAL_TO_OBJECT(mVal));
- return Local<Object>::New(&o);
-}
+// JSScript doesn't have a way to associate private data with it, so we create
+// a custom JSClass that we can instantiate and associate with the script. This
+// way, we can let v8::Script extend v8::Object and work on the custom object
+// instead of on the script itself.
+JSClass script_class = {
+ "v8::ScriptObj", JSCLASS_HAS_PRIVATE,
+ JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_StrictPropertyStub,
+ JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, JS_FinalizeStub,
+ JSCLASS_NO_OPTIONAL_MEMBERS
+};
Local<Script> Script::Create(Handle<String> source, ScriptOrigin *origin, ScriptData *preData,
Handle<String> scriptData, bool bindToCurrentContext) {
JSScript* s = NULL;
@@ -771,9 +771,16 @@ Local<Script> Script::Create(Handle<String> source, ScriptOrigin *origin, Script
return Local<Script>();
}
- Script script(s);
+
+ JSObject *obj = JS_NewObject(cx(), &script_class, NULL, NULL);
+ if (!obj) {
+ return Local<Script>();
+ }
+ JS_SetPrivate(obj, s);
+
+ Script script(obj);
if (bindToCurrentContext) {
- script.InternalObject()->Set(String::New("global"), Context::GetCurrent()->Global());
+ script.Set(String::New("global"), Context::GetCurrent()->Global());
}
return Local<Script>::New(&script);
}
@@ -801,7 +808,7 @@ Local<Script> Script::Compile(Handle<String> source, Handle<Value> fileName,
Local<Value>
Script::Run() {
- Handle<Value> boundGlobalValue = InternalObject()->Get(String::New("global"));
+ Handle<Value> boundGlobalValue = Get(String::New("global"));
Handle<Object> global;
JS_ASSERT(!boundGlobalValue.IsEmpty());
if (boundGlobalValue->IsUndefined()) {
View
15 js/src/v8api/v8.h
@@ -67,11 +67,9 @@ class GCReference {
protected:
jsval mVal;
- js::gc::Cell *mGCCell;
public:
- GCReference(jsval val) : mVal(val), mGCCell(NULL) {}
- GCReference(js::gc::Cell *cell) : mVal(JSVAL_NULL), mGCCell(cell) {}
- GCReference() : mVal(JSVAL_NULL), mGCCell(NULL) {}
+ GCReference(jsval val) : mVal(val) {}
+ GCReference() : mVal(JSVAL_VOID) {}
jsval &native() {
return mVal;
}
@@ -955,16 +953,13 @@ class ScriptData {
friend class Script;
};
-class Script : public internal::GCReference {
- Script(JSScript *s) : GCReference((js::gc::Cell *)s) {};
+class Script : public v8::Object {
+ Script(JSObject *s) : v8::Object(s) {};
-
operator JSScript *() {
- return (JSScript*)mGCCell;
+ return reinterpret_cast<JSScript *>(JS_GetPrivate(*this));
}
- Handle<Object> InternalObject();
-
static Local<Script> Create(Handle<String> source, ScriptOrigin *origin, ScriptData *preData, Handle<String> scriptData, bool bindToCurrentContext);
public:
static Local<Script> New(Handle<String> source, ScriptOrigin *origin = NULL,
Something went wrong with that request. Please try again.