4

I've been fetching rows from a WebSQL DB, and the returned rows seems to be readonly.

    db.readTransaction(
        function(t1) {              
            t1.executeSql(
                "SELECT * FROM Foo WHERE id = ?",
                [1],
                function(t2, resultSet){
                    var foo = resultSet.rows.item(0);

                    console.log("before: " + foo.col1);
                    foo.col1 = "new value";
                    console.log("after: " + foo.col1);
                    console.log("sealed? " + Object.isSealed(foo));
                    console.log("frozen? " + Object.isFrozen(foo));
                }
            );
        }
    );

It prints:

    before: old value
    after: old value
    sealed? false
    frozen? false

I had to manually clone the row to be able to modify it.

How is this possible? How can an object be made immutable without being frozen or sealed? And where in the specs says it should be like that?


UPDATE: It's funny. It only happens in some tables. Still clueless about it.


UPDATE 2: Nope, it happens in every table I read from. Seems to be something related to Chrome (Also happens in Opera, so it might be a webkit behavior).

Mister Smith
  • 27,417
  • 21
  • 110
  • 193

1 Answers1

3

According to the Web SQL Spec SQLResultSetRowList in SQLResultSet Interface is readonly.

gotomanners
  • 7,808
  • 1
  • 24
  • 39
  • The row list maybe, but the row? – Mister Smith Nov 15 '13 at 11:57
  • Theres nothing in the spec about whether a row should be readonly. The properties of `SQLResultSet ` are defined as readonly, and also the `length` property in `SQLResultSetRowList `, but not the items in the returned list. I think WebKit developers did this on their own. And it is amazing, since readonly objects do not exist in classic JavaScript. – Mister Smith Aug 18 '15 at 10:50