/*
- * Copyright (C) 2008, 2009 Apple Inc. All rights reserved.
+ * Copyright (C) 2008, 2009, 2012, 2013 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
#ifndef SourceProvider_h
#define SourceProvider_h
-#include "SourceProviderCache.h"
-#include "UString.h"
#include <wtf/PassOwnPtr.h>
#include <wtf/RefCounted.h>
-#include <wtf/UnusedParam.h>
#include <wtf/text/TextPosition.h>
+#include <wtf/text/WTFString.h>
namespace JSC {
class SourceProvider : public RefCounted<SourceProvider> {
public:
- SourceProvider(const UString& url, SourceProviderCache* cache = 0)
- : m_url(url)
- , m_validated(false)
- , m_cache(cache ? cache : new SourceProviderCache)
- , m_cacheOwned(!cache)
+ static const intptr_t nullID = 1;
+
+ JS_EXPORT_PRIVATE SourceProvider(const String& url, const TextPosition& startPosition);
+
+ JS_EXPORT_PRIVATE virtual ~SourceProvider();
+
+ virtual const String& source() const = 0;
+ String getRange(int start, int end) const
{
+ return source().substringSharingImpl(start, end - start);
}
- virtual ~SourceProvider()
+
+ const String& url() { return m_url; }
+ TextPosition startPosition() const { return m_startPosition; }
+ intptr_t asID()
{
- if (m_cacheOwned)
- delete m_cache;
+ ASSERT(this);
+ if (!this) // Be defensive in release mode.
+ return nullID;
+ if (!m_id)
+ getID();
+ return m_id;
}
- virtual UString getRange(int start, int end) const = 0;
- virtual const UChar* data() const = 0;
- virtual int length() const = 0;
-
- const UString& url() { return m_url; }
- virtual TextPosition1 startPosition() const { return TextPosition1::minimumPosition(); }
- intptr_t asID() { return reinterpret_cast<intptr_t>(this); }
-
bool isValid() const { return m_validated; }
void setValid() { m_validated = true; }
- SourceProviderCache* cache() const { return m_cache; }
- void notifyCacheSizeChanged(int delta) { if (!m_cacheOwned) cacheSizeChanged(delta); }
-
private:
- virtual void cacheSizeChanged(int delta) { UNUSED_PARAM(delta); }
- UString m_url;
- bool m_validated;
- SourceProviderCache* m_cache;
- bool m_cacheOwned;
+ JS_EXPORT_PRIVATE void getID();
+ Vector<size_t>& lineStarts();
+
+ String m_url;
+ TextPosition m_startPosition;
+ bool m_validated : 1;
+ uintptr_t m_id : sizeof(uintptr_t) * 8 - 1;
};
- class UStringSourceProvider : public SourceProvider {
+ class StringSourceProvider : public SourceProvider {
public:
- static PassRefPtr<UStringSourceProvider> create(const UString& source, const UString& url)
+ static PassRefPtr<StringSourceProvider> create(const String& source, const String& url, const TextPosition& startPosition = TextPosition::minimumPosition())
{
- return adoptRef(new UStringSourceProvider(source, url));
+ return adoptRef(new StringSourceProvider(source, url, startPosition));
}
- UString getRange(int start, int end) const
+ virtual const String& source() const OVERRIDE
{
- return m_source.substringSharingImpl(start, end - start);
+ return m_source;
}
- const UChar* data() const { return m_source.characters(); }
- int length() const { return m_source.length(); }
private:
- UStringSourceProvider(const UString& source, const UString& url)
- : SourceProvider(url)
+ StringSourceProvider(const String& source, const String& url, const TextPosition& startPosition)
+ : SourceProvider(url, startPosition)
, m_source(source)
{
}
- UString m_source;
+ String m_source;
};
} // namespace JSC