it's now possible to insert undefined values into JS land
authorerickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Tue, 10 Jan 2006 14:50:18 +0000 (14:50 +0000)
committererickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Tue, 10 Jan 2006 14:50:18 +0000 (14:50 +0000)
JavaScript::SpiderMonkey inserts undefined values as the string "undef" in JS land,
which we can use to check for NULLness

git-svn-id: svn://svn.open-ils.org/ILS/trunk@2670 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/src/perlmods/OpenILS/Utils/SpiderMonkey.pm

index 87ba29d..a1da49e 100644 (file)
@@ -85,7 +85,7 @@ sub insert_method {
 
 sub insert {
        my( $self, $key, $val ) = @_;
-       return unless defined($val);
+       return unless defined($key);
 
        if (ref($val) =~ /^Fieldmapper/o) {
                $self->insert_fm($key, $val);
@@ -96,11 +96,16 @@ sub insert {
        } elsif (ref($val) and $val =~ /CODE/o) {
                $self->context->function_set( $key, $val );
        } elsif (!ref($val)) {
-               $self->context->property_by_path(
-                       $key, $val,
-                       sub { $val },
-                       sub { my( $k, $v ) = @_; $val = $v; }
-               );
+               if( defined($val) ) {
+                       $self->context->property_by_path(
+                               $key, $val,
+                               sub { $val },
+                               sub { my( $k, $v ) = @_; $val = $v; }
+                       );
+               } else {
+                       $self->context->property_by_path($key);
+               }
+
        } else {
                return 0;
        }