diff options
author | Andrej Shadura <andrew.shadura@collabora.co.uk> | 2019-08-28 14:13:29 +0200 |
---|---|---|
committer | Andrej Shadura <andrew.shadura@collabora.co.uk> | 2019-08-29 17:48:13 +0200 |
commit | e19ef5983707e6a5c8d127f1ac8f02754cef82fd (patch) | |
tree | 9e3852cb9abc81ed6aa444465928d45fd7763dea /platform/script-debugger/backend/src/debugger/values |
New upstream version 0~183.5153.4+dfsg
Diffstat (limited to 'platform/script-debugger/backend/src/debugger/values')
11 files changed, 432 insertions, 0 deletions
diff --git a/platform/script-debugger/backend/src/debugger/values/ArrayValue.kt b/platform/script-debugger/backend/src/debugger/values/ArrayValue.kt new file mode 100644 index 00000000..ceed459a --- /dev/null +++ b/platform/script-debugger/backend/src/debugger/values/ArrayValue.kt @@ -0,0 +1,28 @@ +/* + * Copyright 2000-2017 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jetbrains.debugger.values + +interface ArrayValue : ObjectValue { + /** + * Be aware - it is not equals to java array length. + * In case of sparse array `var sparseArray = [3, 4]; + * sparseArray[45] = 34; + * sparseArray[40999995] = "foo"; + ` * + * length will be equal to 40999995. + */ + val length: Int +}
\ No newline at end of file diff --git a/platform/script-debugger/backend/src/debugger/values/FunctionValue.kt b/platform/script-debugger/backend/src/debugger/values/FunctionValue.kt new file mode 100644 index 00000000..2825bc1e --- /dev/null +++ b/platform/script-debugger/backend/src/debugger/values/FunctionValue.kt @@ -0,0 +1,45 @@ +/* + * Copyright 2000-2017 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jetbrains.debugger.values + +import com.intellij.util.ThreeState +import org.jetbrains.concurrency.Promise +import org.jetbrains.debugger.Scope + +interface FunctionValue : ObjectValue { + /** + * You must invoke [.resolve] to use any function value methods + */ + fun resolve(): Promise<FunctionValue> + + /** + * Returns position of opening parenthesis of function arguments. Position is absolute + * within resource (not relative to script start position). + + * @return position or null if position is not available + */ + val openParenLine: Int + + val openParenColumn: Int + + val scopes: Array<Scope>? + + /** + * Method could be called (it is normal and expected) for unresolved function. + * It must return quickly. Return [com.intellij.util.ThreeState.UNSURE] otherwise. + */ + fun hasScopes(): ThreeState = ThreeState.UNSURE +} diff --git a/platform/script-debugger/backend/src/debugger/values/IndexedVariablesConsumer.kt b/platform/script-debugger/backend/src/debugger/values/IndexedVariablesConsumer.kt new file mode 100644 index 00000000..aad2f00d --- /dev/null +++ b/platform/script-debugger/backend/src/debugger/values/IndexedVariablesConsumer.kt @@ -0,0 +1,28 @@ +/* + * Copyright 2000-2017 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jetbrains.debugger.values + +import org.jetbrains.debugger.Variable + +abstract class IndexedVariablesConsumer { + // null if array is not sparse + abstract fun consumeRanges(ranges: IntArray?) + + abstract fun consumeVariables(variables: List<Variable>) + + open val isObsolete: Boolean + get() = false +}
\ No newline at end of file diff --git a/platform/script-debugger/backend/src/debugger/values/ObjectValue.kt b/platform/script-debugger/backend/src/debugger/values/ObjectValue.kt new file mode 100755 index 00000000..55917c42 --- /dev/null +++ b/platform/script-debugger/backend/src/debugger/values/ObjectValue.kt @@ -0,0 +1,53 @@ +/* + * Copyright 2000-2017 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jetbrains.debugger.values + +import com.intellij.util.ThreeState +import org.jetbrains.concurrency.Obsolescent +import org.jetbrains.concurrency.Promise +import org.jetbrains.debugger.EvaluateContext +import org.jetbrains.debugger.Variable +import org.jetbrains.debugger.VariablesHost + +/** + * A compound value that has zero or more properties + */ +interface ObjectValue : Value { + val className: String? + + val properties: Promise<List<Variable>> + + fun getProperties(names: List<String>, evaluateContext: EvaluateContext, obsolescent: Obsolescent): Promise<List<Variable>> + + val variablesHost: VariablesHost<ValueManager> + + /** + * from (inclusive) to (exclusive) ranges of array elements or elements if less than bucketThreshold + + * "to" could be -1 (sometimes length is unknown, so, you can pass -1 instead of actual elements size) + */ + fun getIndexedProperties(from: Int, to: Int, bucketThreshold: Int, consumer: IndexedVariablesConsumer, componentType: ValueType? = null): Promise<*> + + /** + * It must return quickly. Return [com.intellij.util.ThreeState.UNSURE] otherwise. + */ + fun hasProperties(): ThreeState = ThreeState.UNSURE + + /** + * It must return quickly. Return [com.intellij.util.ThreeState.UNSURE] otherwise. + */ + fun hasIndexedProperties(): ThreeState = ThreeState.NO +}
\ No newline at end of file diff --git a/platform/script-debugger/backend/src/debugger/values/ObjectValueBase.kt b/platform/script-debugger/backend/src/debugger/values/ObjectValueBase.kt new file mode 100644 index 00000000..f56adc43 --- /dev/null +++ b/platform/script-debugger/backend/src/debugger/values/ObjectValueBase.kt @@ -0,0 +1,66 @@ +// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +package org.jetbrains.debugger.values + +import com.intellij.util.SmartList +import org.jetbrains.concurrency.* +import org.jetbrains.debugger.EvaluateContext +import org.jetbrains.debugger.Variable +import org.jetbrains.debugger.VariablesHost +import java.util.* + +abstract class ObjectValueBase<VALUE_LOADER : ValueManager>(type: ValueType) : ValueBase(type), ObjectValue { + protected abstract val childrenManager: VariablesHost<VALUE_LOADER> + + override val properties: Promise<List<Variable>> + get() = childrenManager.get() + + internal abstract inner class MyObsolescentAsyncFunction<PARAM, RESULT>(private val obsolescent: Obsolescent) : ObsolescentFunction<PARAM, Promise<RESULT>> { + override fun isObsolete() = obsolescent.isObsolete || childrenManager.valueManager.isObsolete + } + + override fun getProperties(names: List<String>, evaluateContext: EvaluateContext, obsolescent: Obsolescent): Promise<List<Variable>> = properties + .thenAsync(object : MyObsolescentAsyncFunction<List<Variable>, List<Variable>>(obsolescent) { + override fun `fun`(variables: List<Variable>) = getSpecifiedProperties(variables, names, evaluateContext) + }) + + override val valueString: String? = null + + override fun getIndexedProperties(from: Int, to: Int, bucketThreshold: Int, consumer: IndexedVariablesConsumer, componentType: ValueType?): Promise<*> = rejectedPromise<Any?>() + + @Suppress("UNCHECKED_CAST") + override val variablesHost: VariablesHost<ValueManager> + get() = childrenManager as VariablesHost<ValueManager> +} + +fun getSpecifiedProperties(variables: List<Variable>, names: List<String>, evaluateContext: EvaluateContext): Promise<List<Variable>> { + val properties = SmartList<Variable>() + var getterCount = 0 + for (property in variables) { + if (!property.isReadable || !names.contains(property.name)) { + continue + } + + if (!properties.isEmpty()) { + Collections.sort(properties) { o1, o2 -> names.indexOf(o1.name) - names.indexOf(o2.name) } + } + + properties.add(property) + if (property.value == null) { + getterCount++ + } + } + + if (getterCount == 0) { + return resolvedPromise(properties) + } + else { + val promises = SmartList<Promise<*>>() + for (variable in properties) { + if (variable.value == null) { + val valueModifier = variable.valueModifier!! + promises.add(valueModifier.evaluateGet(variable, evaluateContext)) + } + } + return promises.all(properties) + } +}
\ No newline at end of file diff --git a/platform/script-debugger/backend/src/debugger/values/PrimitiveValue.kt b/platform/script-debugger/backend/src/debugger/values/PrimitiveValue.kt new file mode 100644 index 00000000..995e905c --- /dev/null +++ b/platform/script-debugger/backend/src/debugger/values/PrimitiveValue.kt @@ -0,0 +1,45 @@ +/* + * Copyright 2000-2017 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jetbrains.debugger.values + +open class PrimitiveValue(type: ValueType, override val valueString: String) : ValueBase(type) { + + constructor(type: ValueType, value: Int) : this(type, Integer.toString(value)) { + } + + constructor(type: ValueType, value: Long) : this(type, java.lang.Long.toString(value)) { + } + + companion object { + val NA_N_VALUE: String = "NaN" + val INFINITY_VALUE: String = "Infinity" + + @JvmField + val NULL: PrimitiveValue = PrimitiveValue(ValueType.NULL, "null") + @JvmField + val UNDEFINED: PrimitiveValue = PrimitiveValue(ValueType.UNDEFINED, "undefined") + + val NAN: PrimitiveValue = PrimitiveValue(ValueType.NUMBER, NA_N_VALUE) + val INFINITY: PrimitiveValue = PrimitiveValue(ValueType.NUMBER, INFINITY_VALUE) + + private val TRUE = PrimitiveValue(ValueType.BOOLEAN, "true") + private val FALSE = PrimitiveValue(ValueType.BOOLEAN, "false") + + fun bool(value: String): PrimitiveValue { + return if (value == "true") TRUE else FALSE + } + } +}
\ No newline at end of file diff --git a/platform/script-debugger/backend/src/debugger/values/StringValue.kt b/platform/script-debugger/backend/src/debugger/values/StringValue.kt new file mode 100644 index 00000000..8a1e8c48 --- /dev/null +++ b/platform/script-debugger/backend/src/debugger/values/StringValue.kt @@ -0,0 +1,29 @@ +/* + * Copyright 2000-2017 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jetbrains.debugger.values + +import org.jetbrains.concurrency.Promise + +interface StringValue : Value { + val isTruncated: Boolean + + val length: Int + + /** + * Asynchronously reloads object value with extended size limit + */ + val fullString: Promise<String> +}
\ No newline at end of file diff --git a/platform/script-debugger/backend/src/debugger/values/Value.kt b/platform/script-debugger/backend/src/debugger/values/Value.kt new file mode 100755 index 00000000..79846ce9 --- /dev/null +++ b/platform/script-debugger/backend/src/debugger/values/Value.kt @@ -0,0 +1,28 @@ +/* + * Copyright 2000-2017 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jetbrains.debugger.values + +/** + * An object that represents a VM variable value (compound or atomic). + */ +interface Value { + val type: ValueType + + /** + * @return a string representation of this value + */ + val valueString: String? +}
\ No newline at end of file diff --git a/platform/script-debugger/backend/src/debugger/values/ValueBase.kt b/platform/script-debugger/backend/src/debugger/values/ValueBase.kt new file mode 100644 index 00000000..2d62611a --- /dev/null +++ b/platform/script-debugger/backend/src/debugger/values/ValueBase.kt @@ -0,0 +1,18 @@ +/* + * Copyright 2000-2017 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jetbrains.debugger.values + +abstract class ValueBase(override val type: ValueType) : Value
\ No newline at end of file diff --git a/platform/script-debugger/backend/src/debugger/values/ValueManager.kt b/platform/script-debugger/backend/src/debugger/values/ValueManager.kt new file mode 100644 index 00000000..4d7eb248 --- /dev/null +++ b/platform/script-debugger/backend/src/debugger/values/ValueManager.kt @@ -0,0 +1,43 @@ +/* + * Copyright 2000-2017 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jetbrains.debugger.values + +import org.jetbrains.concurrency.Obsolescent +import java.util.concurrent.atomic.AtomicInteger + +/** + * The main idea of this class - don't create value for remote value handle if already exists. So, + * implementation of this class keep map of value to remote value handle. + * Also, this class maintains cache timestamp. + + * Currently WIP implementation doesn't keep such map due to protocol issue. But V8 does. + */ +abstract class ValueManager() : Obsolescent { + private val cacheStamp = AtomicInteger() + @Volatile private var obsolete = false + + open fun clearCaches() { + cacheStamp.incrementAndGet() + } + + fun getCacheStamp(): Int = cacheStamp.get() + + final override fun isObsolete(): Boolean = obsolete + + fun markObsolete() { + obsolete = true + } +}
\ No newline at end of file diff --git a/platform/script-debugger/backend/src/debugger/values/ValueType.kt b/platform/script-debugger/backend/src/debugger/values/ValueType.kt new file mode 100644 index 00000000..591e827b --- /dev/null +++ b/platform/script-debugger/backend/src/debugger/values/ValueType.kt @@ -0,0 +1,49 @@ +/* + * Copyright 2000-2017 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jetbrains.debugger.values + +private val VALUE_TYPES = ValueType.values() + +/** + * Don't forget to update NashornDebuggerSupport.ValueType and DebuggerSupport.ts respectively also + */ +enum class ValueType { + OBJECT, + NUMBER, + STRING, + FUNCTION, + BOOLEAN, + BIGINT, + + ARRAY, + NODE, + + UNDEFINED, + NULL, + SYMBOL; + + /** + * Returns whether `type` corresponds to a JsObject. Note that while 'null' is an object + * in JavaScript world, here for API consistency it has bogus type [.NULL] and is + * not a [ObjectValue] + */ + val isObjectType: Boolean + get() = this == OBJECT || this == ARRAY || this == FUNCTION || this == NODE + + companion object { + fun fromIndex(index: Int): ValueType = VALUE_TYPES.get(index) + } +}
\ No newline at end of file |