Ignore:
Timestamp:
Aug 15, 2008, 12:43:48 AM (17 years ago)
Author:
[email protected]
Message:

Reviewed by Geoff Garen.

JSStringRef is created context-free, but can get linked to one via an identifier table,
breaking an implicit API contract.

Made JSStringRef point to OpaqueJSString, which is a new string object separate from UString.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/API/JSCallbackObjectFunctions.h

    r35478 r35775  
    3434#include "JSString.h"
    3535#include "JSStringRef.h"
     36#include "OpaqueJSString.h"
    3637#include "PropertyNameArray.h"
    3738#include <wtf/Vector.h>
     
    106107    JSContextRef ctx = toRef(exec);
    107108    JSObjectRef thisRef = toRef(this);
    108     JSStringRef propertyNameRef = toRef(propertyName.ustring().rep());
     109    RefPtr<OpaqueJSString> propertyNameRef;
    109110   
    110111    for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parentClass) {
    111112        // optional optimization to bypass getProperty in cases when we only need to know if the property exists
    112113        if (JSObjectHasPropertyCallback hasProperty = jsClass->hasProperty) {
    113             if (hasProperty(ctx, thisRef, propertyNameRef)) {
     114            if (!propertyNameRef)
     115                propertyNameRef = OpaqueJSString::create(propertyName.ustring());
     116            if (hasProperty(ctx, thisRef, propertyNameRef.get())) {
    114117                slot.setCustom(this, callbackGetter);
    115118                return true;
    116119            }
    117120        } else if (JSObjectGetPropertyCallback getProperty = jsClass->getProperty) {
    118             if (JSValueRef value = getProperty(ctx, thisRef, propertyNameRef, toRef(exec->exceptionSlot()))) {
     121            if (!propertyNameRef)
     122                propertyNameRef = OpaqueJSString::create(propertyName.ustring());
     123            if (JSValueRef value = getProperty(ctx, thisRef, propertyNameRef.get(), toRef(exec->exceptionSlot()))) {
    119124                // cache the value so we don't have to compute it again
    120125                // FIXME: This violates the PropertySlot design a little bit.
     
    154159    JSContextRef ctx = toRef(exec);
    155160    JSObjectRef thisRef = toRef(this);
    156     JSStringRef propertyNameRef = toRef(propertyName.ustring().rep());
     161    RefPtr<OpaqueJSString> propertyNameRef;
    157162    JSValueRef valueRef = toRef(value);
    158163   
    159164    for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parentClass) {
    160165        if (JSObjectSetPropertyCallback setProperty = jsClass->setProperty) {
    161             if (setProperty(ctx, thisRef, propertyNameRef, valueRef, toRef(exec->exceptionSlot())))
     166            if (!propertyNameRef)
     167                propertyNameRef = OpaqueJSString::create(propertyName.ustring());
     168            if (setProperty(ctx, thisRef, propertyNameRef.get(), valueRef, toRef(exec->exceptionSlot())))
    162169                return;
    163170        }
     
    168175                    return;
    169176                if (JSObjectSetPropertyCallback setProperty = entry->setProperty) {
    170                     if (setProperty(ctx, thisRef, propertyNameRef, valueRef, toRef(exec->exceptionSlot())))
     177                    if (!propertyNameRef)
     178                        propertyNameRef = OpaqueJSString::create(propertyName.ustring());
     179                    if (setProperty(ctx, thisRef, propertyNameRef.get(), valueRef, toRef(exec->exceptionSlot())))
    171180                        return;
    172181                } else
     
    199208    JSContextRef ctx = toRef(exec);
    200209    JSObjectRef thisRef = toRef(this);
    201     JSStringRef propertyNameRef = toRef(propertyName.ustring().rep());
     210    RefPtr<OpaqueJSString> propertyNameRef;
    202211   
    203212    for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parentClass) {
    204213        if (JSObjectDeletePropertyCallback deleteProperty = jsClass->deleteProperty) {
    205             if (deleteProperty(ctx, thisRef, propertyNameRef, toRef(exec->exceptionSlot())))
     214            if (!propertyNameRef)
     215                propertyNameRef = OpaqueJSString::create(propertyName.ustring());
     216            if (deleteProperty(ctx, thisRef, propertyNameRef.get(), toRef(exec->exceptionSlot())))
    206217                return true;
    207218        }
     
    431442   
    432443    JSObjectRef thisRef = toRef(thisObj);
    433     JSStringRef propertyNameRef = toRef(propertyName.ustring().rep());
     444    RefPtr<OpaqueJSString> propertyNameRef;
    434445   
    435446    for (JSClassRef jsClass = thisObj->m_class; jsClass; jsClass = jsClass->parentClass)
     
    437448            if (StaticValueEntry* entry = staticValues->get(propertyName.ustring().rep()))
    438449                if (JSObjectGetPropertyCallback getProperty = entry->getProperty) {
    439                     if (JSValueRef value = getProperty(toRef(exec), thisRef, propertyNameRef, toRef(exec->exceptionSlot())))
     450                    if (!propertyNameRef)
     451                        propertyNameRef = OpaqueJSString::create(propertyName.ustring());
     452                    if (JSValueRef value = getProperty(toRef(exec), thisRef, propertyNameRef.get(), toRef(exec->exceptionSlot())))
    440453                        return toJS(value);
    441454                }
     
    477490   
    478491    JSObjectRef thisRef = toRef(thisObj);
    479     JSStringRef propertyNameRef = toRef(propertyName.ustring().rep());
     492    RefPtr<OpaqueJSString> propertyNameRef;
    480493   
    481494    for (JSClassRef jsClass = thisObj->m_class; jsClass; jsClass = jsClass->parentClass)
    482495        if (JSObjectGetPropertyCallback getProperty = jsClass->getProperty) {
    483             if (JSValueRef value = getProperty(toRef(exec), thisRef, propertyNameRef, toRef(exec->exceptionSlot())))
     496            if (!propertyNameRef)
     497                propertyNameRef = OpaqueJSString::create(propertyName.ustring());
     498            if (JSValueRef value = getProperty(toRef(exec), thisRef, propertyNameRef.get(), toRef(exec->exceptionSlot())))
    484499                return toJS(value);
    485500        }
Note: See TracChangeset for help on using the changeset viewer.