From 5edb205978f073bc32cc0e68452d972d068bd808 Mon Sep 17 00:00:00 2001 From: Ari Lazier Date: Thu, 15 Oct 2015 19:48:46 -0700 Subject: [PATCH] clean up prototype and defaults state --- src/RJSSchema.hpp | 1 + src/RJSSchema.mm | 14 ++++++++++++++ src/RealmJS.mm | 2 ++ 3 files changed, 17 insertions(+) diff --git a/src/RJSSchema.hpp b/src/RJSSchema.hpp index 8faa8f5a..0ca94790 100644 --- a/src/RJSSchema.hpp +++ b/src/RJSSchema.hpp @@ -31,3 +31,4 @@ realm::Schema RJSParseSchema(JSContextRef ctx, JSObjectRef jsonObject); JSValueRef RJSPrototypeForClassName(const std::string &className); realm::ObjectDefaults &RJSDefaultsForClassName(const std::string &className); +void RJSSchemaClearState(JSContextRef ctx); \ No newline at end of file diff --git a/src/RJSSchema.mm b/src/RJSSchema.mm index ef9fdb12..4b00eb96 100644 --- a/src/RJSSchema.mm +++ b/src/RJSSchema.mm @@ -55,6 +55,20 @@ JSValueRef RJSPrototypeForClassName(const std::string &className) { return s_prototypes[className]; } +void RJSSchemaClearState(JSContextRef ctx) { + for (auto prototype : s_prototypes) { + JSValueUnprotect(ctx, prototype.second); + } + s_prototypes.clear(); + + for (auto defaults : s_defaults) { + for (auto value : defaults.second) { + JSValueUnprotect(ctx, value.second); + } + } + s_defaults.clear(); +} + static inline Property RJSParseProperty(JSContextRef ctx, JSObjectRef propertyObject) { static JSStringRef nameString = JSStringCreateWithUTF8CString("name"); static JSStringRef typeString = JSStringCreateWithUTF8CString("type"); diff --git a/src/RealmJS.mm b/src/RealmJS.mm index 589ae7a4..15aecb5c 100644 --- a/src/RealmJS.mm +++ b/src/RealmJS.mm @@ -20,6 +20,7 @@ #import "RJSRealm.hpp" #import "RJSObject.hpp" #import "RJSUtil.hpp" +#import "RJSSchema.hpp" #include "shared_realm.hpp" @@ -57,6 +58,7 @@ NSString *RealmFileDirectory() { static JSValueRef ClearTestState(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception) { [RealmJS clearTestState]; + RJSSchemaClearState(ctx); return NULL; }